Mobject
(color='#FFFFFF', name=None, dim=3, target=None, z_index=0, **kwargs)[source]¶Bases: manim.container.Container
Mathematical Object: base class for objects that can be displayed on screen.
Methods
Add mobjects as submobjects. |
|
|
|
|
|
|
|
|
|
Adds (or moves) all passed mobjects to the back of the scene. |
|
Add an update function to this mobject. |
|
|
|
Direction just needs to be a vector pointing towards side or corner in the 2d plane. |
|
|
|
|
|
|
|
Examples: mob1.align_to(mob2, UP) moves mob1 vertically so that its top edge lines ups with mob2’s top edge. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sort mobjects next to each other on screen. |
|
|
|
|
|
Edit points, colors and submobjects to be identical to another mobject |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Meant to generalize get_x, get_y, get_z |
|
|
|
Picture a box bounding the mobject. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The simplest mobject to be transformed to or from self. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Turns this mobject into an interpolation between |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Move this mobject next to another mobject or coordinate. |
|
|
|
If a mobject with points is being aligned to one without, treat both as groups, and push the one with points into its own submobjects list. |
|
|
|
|
|
|
|
|
|
|
|
|
|
Remove submobjects. |
|
|
|
This can make transition animations nicer |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Default behavior is to scale about the center of the mobject. |
|
|
|
|
|
Condition is function which takes in one arguments, (x, y, z). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sets the mobject’s |
|
Sets the mobject’s z coordinate to the value of |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Attributes
Used to animate the application of a method. |
add
(*mobjects)[source]¶Add mobjects as submobjects.
The mobjects are added to self.submobjects.
Subclasses of mobject may implement + and += dunder methods.
mobjects (Mobject
) – The mobjects to add.
self
ValueError – When a mobject tries to add itself.
TypeError – When trying to add an object that is not an instance of Mobject
.
Notes
A mobject cannot contain itself, and it cannot contain a submobject more than once. If the parent mobject is displayed, the newly-added submobjects will also be displayed (i.e. they are automatically added to the parent Scene).
See also
Examples
>>> outer = Mobject()
>>> inner = Mobject()
>>> outer = outer.add(inner)
Duplicates are not added again:
>>> outer = outer.add(inner)
>>> len(outer.submobjects)
1
Adding an object to itself raises an error:
>>> outer.add(outer)
Traceback (most recent call last):
...
ValueError: Mobject cannot contain self
add_to_back
(*mobjects)[source]¶Adds (or moves) all passed mobjects to the back of the scene.
Note
Technically, this is done by adding (or moving) the mobjects to
the head of self.submobjects
. The head of this list is rendered
first, which places the corresponding mobjects behind the
subsequent list members.
add_updater
(update_function, index=None, call_updater=False)[source]¶Add an update function to this mobject.
Examples
class RotationUpdater(Scene):
def construct(self):
def updater_forth(mobj, dt):
mobj.rotate_about_origin(dt)
def updater_back(mobj, dt):
mobj.rotate_about_origin(-dt)
line_reference = Line(ORIGIN, LEFT).set_color(WHITE)
line_moving = Line(ORIGIN, LEFT).set_color(YELLOW)
line_moving.add_updater(updater_forth)
self.add(line_reference, line_moving)
self.wait(2)
line_moving.remove_updater(updater_forth)
line_moving.add_updater(updater_back)
self.wait(2)
line_moving.remove_updater(updater_back)
self.wait(0.5)
align_on_border
(direction, buff=0.5)[source]¶Direction just needs to be a vector pointing towards side or corner in the 2d plane.
align_to
(mobject_or_point, direction=array([0.0, 0.0, 0.0]), alignment_vect=array([0.0, 1.0, 0.0]))[source]¶Examples: mob1.align_to(mob2, UP) moves mob1 vertically so that its top edge lines ups with mob2’s top edge.
mob1.align_to(mob2, alignment_vect = RIGHT) moves mob1 horizontally so that it’s center is directly above/below the center of mob2
animate
[source]¶Used to animate the application of a method.
Warning
Passing multiple animations for the same Mobject
in one
call to play()
is discouraged and will most likely
not work properly. Instead of writing an animation like
self.play(my_mobject.animate.shift(RIGHT), my_mobject.animate.rotate(PI))
make use of method chaining for animate
, meaning:
self.play(my_mobject.animate.shift(RIGHT).rotate(PI))
See also
override_animate()
Examples
class AnimateExample(Scene):
def construct(self):
s = Square()
self.play(ShowCreation(s))
self.play(s.animate.shift(RIGHT))
self.play(s.animate.scale(2))
self.play(s.animate.rotate(PI / 2))
self.play(Uncreate(s))
class AnimateChainExample(Scene):
def construct(self):
s = Square()
self.play(ShowCreation(s))
self.play(s.animate.shift(RIGHT).scale(2).rotate(PI / 2))
self.play(Uncreate(s))
arrange
(direction=array([1.0, 0.0, 0.0]), buff=0.25, center=True, **kwargs)[source]¶sort mobjects next to each other on screen.
Examples
class Example(Scene):
def construct(self):
s1 = Square()
s2 = Square()
s3 = Square()
s4 = Square()
x = VGroup(s1, s2, s3, s4).set_x(0).arrange(buff=1.0)
self.add(x)
become
(mobject, copy_submobjects=True)[source]¶Edit points, colors and submobjects to be identical to another mobject
Examples
class BecomeScene(Scene):
def construct(self):
circ = Circle(fill_color=RED)
square = Square(fill_color=BLUE)
self.add(circ)
self.wait(0.5)
circ.become(square)
self.wait(0.5)
get_critical_point
(direction)[source]¶Picture a box bounding the mobject. Such a box has 9 ‘critical points’: 4 corners, 4 edge center, the center. This returns one of them.
get_point_mobject
(center=None)[source]¶The simplest mobject to be transformed to or from self. Should by a point of the appropriate type
interpolate
(mobject1, mobject2, alpha, path_func=<function straight_path>)[source]¶Turns this mobject into an interpolation between mobject1
and mobject2
.
Examples
class DotInterpolation(Scene):
def construct(self):
dotL = Dot(color=DARK_GREY)
dotL.shift(2 * RIGHT)
dotR = Dot(color=WHITE)
dotR.shift(2 * LEFT)
dotMiddle = VMobject().interpolate(dotL, dotR, alpha=0.3)
self.add(dotL, dotR, dotMiddle)
next_to
(mobject_or_point, direction=array([1.0, 0.0, 0.0]), buff=0.25, aligned_edge=array([0.0, 0.0, 0.0]), submobject_to_align=None, index_of_submobject_to_align=None, coor_mask=array([1, 1, 1]))[source]¶Move this mobject next to another mobject or coordinate.
Examples
class GeometricShapes(Scene):
def construct(self):
d = Dot()
c = Circle()
s = Square()
t = Triangle()
d.next_to(c, RIGHT)
s.next_to(c, LEFT)
t.next_to(c, DOWN)
self.add(d, c, s, t)
null_point_align
(mobject)[source]¶If a mobject with points is being aligned to one without, treat both as groups, and push the one with points into its own submobjects list.
remove
(*mobjects)[source]¶Remove submobjects.
The mobjects are removed from self.submobjects, if they exist.
Subclasses of mobject may implement - and -= dunder methods.
See also
scale
(scale_factor, **kwargs)[source]¶Default behavior is to scale about the center of the mobject. The argument about_edge can be a vector, indicating which side of the mobject to scale about, e.g., mob.scale(about_edge = RIGHT) scales about mob.get_right().
Otherwise, if about_point is given a value, scaling is done with respect to that point.
set_color
(color='#FFFF00', family=True)[source]¶Condition is function which takes in one arguments, (x, y, z). Here it just recurses to submobjects, but in subclasses this should be further implemented based on the the inner workings of color