manim.mobject.mobject.Mobject

class 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.

submobjects[source]

The contained objects.

Type

list

Methods

add

Add mobjects as submobjects.

add_background_rectangle

add_background_rectangle_to_family_members_with_points

add_background_rectangle_to_submobjects

add_n_more_submobjects

add_to_back

Adds (or moves) all passed mobjects to the back of the scene.

add_updater

Add an update function to this mobject.

align_data

align_on_border

Direction just needs to be a vector pointing towards side or corner in the 2d plane.

align_points

align_points_with_larger

align_submobjects

align_to

Examples: mob1.align_to(mob2, UP) moves mob1 vertically so that its top edge lines ups with mob2’s top edge.

apply_complex_function

apply_function

apply_function_to_position

apply_function_to_submobject_positions

apply_matrix

apply_over_attr_arrays

apply_points_function_about_point

apply_to_family

arrange

sort mobjects next to each other on screen.

arrange_in_grid

arrange_submobjects

become

Edit points, colors and submobjects to be identical to another mobject

center

clear_updaters

copy

fade

fade_to

family_members_with_points

flip

generate_points

generate_target

get_all_points

get_array_attrs

get_bottom

get_boundary_point

get_center

get_center_of_mass

get_color

get_coord

Meant to generalize get_x, get_y, get_z

get_corner

get_critical_point

Picture a box bounding the mobject.

get_depth

get_edge_center

get_end

get_extremum_along_dim

get_family

get_family_updaters

get_group_class

get_height

get_image

get_left

get_merged_array

get_nadir

get_num_points

get_pieces

get_point_mobject

The simplest mobject to be transformed to or from self.

get_points_defining_boundary

get_right

get_start

get_start_and_end

get_time_based_updaters

get_top

get_updaters

get_width

get_x

get_y

get_z

get_z_index_reference_point

get_zenith

has_no_points

has_points

has_time_based_updater

init_colors

interpolate

Turns this mobject into an interpolation between mobject1 and mobject2.

interpolate_color

is_off_screen

length_over_dim

match_color

match_coord

match_depth

match_dim_size

match_height

match_updaters

match_width

match_x

match_y

match_z

move_to

next_to

Move this mobject next to another mobject or coordinate.

nonempty_submobjects

null_point_align

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.

point_from_proportion

pointwise_become_partial

pose_at_angle

push_self_into_submobjects

put_start_and_end_on

reduce_across_dimension

remove

Remove submobjects.

remove_updater

repeat

This can make transition animations nicer

repeat_submobject

replace

rescale_to_fit

reset_points

restore

resume_updating

reverse_points

rotate

rotate_about_origin

rotate_in_place

save_image

save_state

scale

Default behavior is to scale about the center of the mobject.

scale_about_point

scale_in_place

set_color

Condition is function which takes in one arguments, (x, y, z).

set_color_by_gradient

set_colors_by_radial_gradient

set_coord

set_depth

set_height

set_submobject_colors_by_gradient

set_submobject_colors_by_radial_gradient

set_width

set_x

set_y

set_z

set_z_index

Sets the mobject’s z_index to the value specified in z_index_value.

set_z_index_by_z_coordinate

Sets the mobject’s z coordinate to the value of z_index.

shift

shift_onto_screen

show

shuffle

shuffle_submobjects

sort

sort_submobjects

space_out_submobjects

split

stretch

stretch_about_point

stretch_in_place

stretch_to_fit_depth

stretch_to_fit_height

stretch_to_fit_width

surround

suspend_updating

throw_error_if_no_points

to_corner

to_edge

to_original_color

update

wag

Attributes

animate

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.

Parameters

mobjects (Mobject) – The mobjects to add.

Returns

self

Return type

Mobject

Raises
  • 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

remove()

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

RotationUpdater
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

property 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

AnimateExample
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))
AnimateChainExample
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

../_images/Example-2.png
Example
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

BecomeScene
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_coord(dim, direction=array([0.0, 0.0, 0.0]))[source]

Meant to generalize get_x, get_y, get_z

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

../_images/DotInterpolation-1.png
DotInterpolation
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

../_images/GeometricShapes-1.png
GeometricShapes
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.

Parameters

mobjects (Mobject) – The mobjects to remove.

Returns

self

Return type

Mobject

See also

add()

repeat(count)[source]

This can make transition animations nicer

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

set_z_index(z_index_value)[source]

Sets the mobject’s z_index to the value specified in z_index_value.

Parameters

z_index_value (Union[int, float]) – The new value of z_index set.

Returns

The Mobject itself, after z_index is set. (Returns self.)

Return type

Mobject

set_z_index_by_z_coordinate()[source]

Sets the mobject’s z coordinate to the value of z_index.

Returns

The Mobject itself, after z_index is set. (Returns self.)

Return type

Mobject