Skip to content

Mobjects

The film's code
import manimgx as m


class MobjectsHero(m.Scene):
    def construct(self) -> None:
        def curve(x: float) -> float:
            return 0.5 * x**2

        axes = m.Axes(x_range=[-2, 2, 1], y_range=[0, 2, 1], x_length=3.2, y_length=2.2)
        graph = axes.plot(curve, color=m.BLUE)
        kinds = m.VGroup(
            m.Square(color=m.BLUE, fill_opacity=0.5),
            m.Star(color=m.YELLOW, fill_opacity=0.5),
            m.Arrow(m.LEFT, m.RIGHT, color=m.GREEN),
            m.Text("Text", font_size=64),
            m.MathTex(r"e^{i\pi} + 1 = 0", font_size=56),
            m.VGroup(axes, graph),
        )
        kinds.arrange_in_grid(rows=2, buff=(1.2, 1))
        self.play(
            m.LaggedStart(
                *[m.FadeIn(kind, shift=0.3 * m.UP) for kind in kinds], lag_ratio=0.15
            )
        )
        self.wait()

A mobject is anything a video shows: a shape, a text, a formula, a graph. Making a mobject doesn't show it: add it to the scene, or play an animation that brings it in.

Every mobject has three things:

  • Points, which give its place and its shape. They are in units: the frame's short side is 8 units, and its center is the point [0, 0, 0].
  • A style: the color and opacity of its stroke and of its fill.
  • Parts, which are mobjects too: a group's members, a formula's terms, a graph's axes. What you do to a mobject, you do to all its parts.

Every mobject can do what the first pages tell, whatever its kind: be placed, sized and turned, styled, grouped and copied. The pages after them tell each kind of mobject.

What every mobject can do

  • Positions


    Points and directions, and the methods that place a mobject: at a point, by another mobject, at the frame's edge.

  • Size and angle


    Scale, stretch, turn and flip a mobject, or move every point through a function.

  • Style


    Stroke and fill, color and opacity, gradients, and what covers what.

  • Colors


    The named colors, and the functions that make, blend and choose colors.

  • Groups


    Mobjects made of mobjects: add, remove, arrange and sort the parts.

  • Copies and states


    Copy a mobject, keep its state to come back to, and prepare a state to move to.

  • Paths


    The curves a shape is made of: draw a path of your own, and find points along one.

Kinds of mobjects

  • Shapes


    Lines and arrows, circles and arcs, polygons, and shapes made from other shapes.

  • Annotations


    Braces, labels, frames, underlines and angle marks: what points at other mobjects.

  • Text and math


    Words, formulas and numbers, set by Typst inside manimgx.

  • Graphs


    Axes, number lines and planes, the graphs of functions and data, vector fields.

  • Networks


    Vertices joined by edges, laid out for you, which grow and change.

  • Matrices and tables


    Entries in rows and columns, between brackets or between lines.

  • Images and SVG


    Pictures from files or pixels, and drawings read from SVG files.

  • Point clouds


    Mobjects drawn as points, each a dot of its own color.

The mobject

Mobject

The object everything in a scene is made of: shapes, text, groups, trackers.

A mobject has points in scene coordinates (x to the right, y up, z out of the screen; the frame is 8 units on its short side, about 14.2 × 8 at 16:9, centered on the origin); submobjects, a tree drawn and moved with it; a style: its fill, its stroke and their colors; updaters, which change it as time passes; and a z-index, its place in the drawing order. You make one through its subclasses — Circle, Text, VGroup and the rest — and they all share the methods here: to transform it (shift, scale, rotate), lay it out (next_to, arrange), style it (set_color), keep it updated (add_updater), and animate any of that (animate).

A transformation or a style acts on the mobject's whole family — the mobject, its submobjects, theirs, and so on — and returns the mobject, so calls chain: Square().scale(2).set_color(BLUE). Size and layout go by the mobject's bounding box: the smallest box, aligned with the axes, around what it draws.

m.Mobject(**kwargs)
color

The color of both fill and stroke (default white); None for the class's default.

fill_color

The fill's color; color if not given. Several colors make a gradient along sheen_direction.

fill_opacity

The fill's opacity, from 0 to 1 (default 0: no fill).

stroke_color

The stroke's color; color if not given. Several colors make a gradient.

stroke_opacity

The stroke's opacity, from 0 to 1 (default 1).

stroke_width

The stroke's width, in hundredths of a scene unit (default 4; 0: no stroke).

background_stroke_color

The color of an outline drawn behind the fill (default black).

background_stroke_opacity

The outline's opacity, from 0 to 1 (default 1).

background_stroke_width

The outline's width, in hundredths of a scene unit (default 0: none).

sheen_factor

How much the colors lighten toward sheen_direction, from -1 to 1 (default 0); a negative factor darkens.

sheen_direction

The direction the colors lighten toward (default UL).

joint_type

How the stroke is joined where its path turns: round, beveled or mitered, as a two-dimensional scene draws it (see LineJointType; default AUTO: mitered).

cap_style

How the stroke ends, at each end it shows (an open path's, a dash's): round, butt or square, as a two-dimensional scene draws it (see CapStyleType; default AUTO: butt).

shade_in_3d

Whether a three-dimensional scene's light shades the mobject.

material

How its surface reflects the scene's lights in a three-dimensional scene (see Material); None: Manim's shading (default).

name

A name for the mobject; its class's name if not given.

z_index

Its place in the drawing order: a higher index is drawn over a lower one (default 0).

target

The state MoveToTarget moves the mobject to.

It also takes the style keywords.

Source

src/manimgx/mobject.py

def __init__(self, **kwargs: Unpack[Style]) -> None:
    if (
        "color" in kwargs and kwargs["color"] is None
    ):  # not given: the class's default
        del kwargs["color"]
    self.style = style_defaults(type(self)) | kwargs
    """Pending constructor style, including the class's defaults. Base color
    initialization consumes this instance entry; current appearance is kept in
    [paint][manimgx.Mobject.paint]. Point clouds retain their defaults for later points."""
    name = self.style.get("name")
    self.name = type(self).__name__ if name is None else name
    """The mobject's name: its class's name, unless it was made with one."""
    self.dim = 3
    """How many coordinates each of its points has: 3."""
    self.target: Mobject | None = self.style.get("target")
    """The state [MoveToTarget][manimgx.MoveToTarget] moves the mobject to: made by
    [generate_target][manimgx.Mobject.generate_target], or given when the mobject
    was made; None if neither."""
    self.z_index = self.style.get("z_index", 0.0)
    """The mobject's place in the drawing order: a higher index is drawn over a
    lower one (default 0); see [set_z_index][manimgx.Mobject.set_z_index]."""
    self.submobjects: list[Mobject] = []
    """The mobject's children, in drawing order: each is drawn over those before it,
    at an equal z-index."""
    self.updaters: list[Updater[Self]] = []
    """The mobject's own updaters, in the order they run; see
    [add_updater][manimgx.Mobject.add_updater]."""
    self.updating_suspended = False
    """Whether the mobject's updaters are suspended; see
    [suspend_updating][manimgx.Mobject.suspend_updating]."""
    self.paint = _UNPAINTED
    """The mobject's own style as it is now, as one value: its colors, opacities,
    stroke widths and sheen. The style methods replace it; it is never changed in
    place."""
    self.reset_points()
    self.generate_points()
    self.init_colors()

submobjects

The mobject's children, in drawing order: each is drawn over those before it, at an equal z-index.

name

The mobject's name: its class's name, unless it was made with one.