Skip to content

Annotations

The film's code
import manimgx as m


class AnnotationsHero(m.Scene):
    def construct(self) -> None:
        formula = m.MathTex(r"a^2 + b^2 = c^2", font_size=72).shift(1.5 * m.UP)
        brace = m.Brace(formula[0][:5], m.DOWN, color=m.YELLOW)
        note = brace.get_text("the legs")
        frame = m.SurroundingRectangle(formula[0][6:], color=m.BLUE)
        a, b, c = [-1.5, -3, 0], [1.5, -3, 0], [1.5, -0.8, 0]
        triangle = m.Polygon(a, b, c, color=m.WHITE)
        right = m.RightAngle(m.Line(b, a), m.Line(b, c), length=0.35, color=m.GREEN)
        angle = m.Angle(m.Line(a, b), m.Line(a, c), radius=0.8, color=m.RED)
        self.play(m.Write(formula))
        self.play(m.GrowFromCenter(brace), m.FadeIn(note), m.Create(frame))
        self.play(m.Create(triangle), m.Create(right), m.Create(angle))
        self.wait()

An annotation points at another mobject, frames it, labels it or measures it. Most take the mobject when you make them and fit it: a brace as long as its side, a frame around it, a line under it. They don't follow it afterward; to make one follow, redraw it at every frame with always_redraw.

Braces

Brace

Code
import manimgx as m


class BraceExample(m.Scene):
    def construct(self) -> None:
        square = m.Square(side_length=3, color=m.BLUE, fill_opacity=0.5)
        self.add(square)
        self.play(
            m.GrowFromCenter(m.Brace(square)),
            m.GrowFromCenter(m.Brace(square, m.RIGHT, color=m.YELLOW)),
            m.GrowFromCenter(m.Brace(square, m.UP, buff=0.5, color=m.GREEN)),
        )

A curly brace along a side of a mobject, as long as the mobject is wide there: filled white, without an outline, unless styled.

The brace lies buff beyond the mobject's bounding box, on the side direction points to, spanning the mobject across that direction, its tip pointing away; the mobject is left as it is. get_text and get_tex label its tip.

m.Brace(mobject, direction=DOWN, buff=0.2, sharpness=2, **kwargs)
mobject

The mobject to brace.

direction

The side the brace is on, as a direction (DOWN: below).

buff

The gap between the mobject and the brace, in scene units.

sharpness

How sharp the brace's tip and ends are: the higher, the narrower its curls.

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/mobjects/annotations.py

def __init__(
    self,
    mobject: Mobject,
    direction: Vector3DLike = DOWN,
    buff: float = 0.2,
    sharpness: float = 2,
    **kwargs: Unpack[Style],
):
    path_string_template = (
        "m0.01216 0c-0.01152 0-0.01216 6.103e-4 -0.01216 0.01311v0.007762c0.06776"
        " 0.122 0.1799 0.1455 0.2307 0.1455h{0}c0.03046 3.899e-4 0.07964 0.00449"
        " 0.1246 0.02636 0.0537 0.02695 0.07418 0.05816 0.08648 0.07769 0.001562"
        " 0.002538 0.004539 0.002563 0.01098 0.002563 0.006444-2e-8"
        " 0.009421-2.47e-5 0.01098-0.002563 0.0123-0.01953 0.03278-0.05074"
        " 0.08648-0.07769 0.04491-0.02187 0.09409-0.02597"
        " 0.1246-0.02636h{0}c0.05077 0 0.1629-0.02346"
        " 0.2307-0.1455v-0.007762c-1.78e-6 -0.0125-6.365e-4"
        " -0.01311-0.01216-0.01311-0.006444-3.919e-8 -0.009348 2.448e-5 -0.01091"
        " 0.002563-0.0123 0.01953-0.03278 0.05074-0.08648 0.07769-0.04491"
        " 0.02187-0.09416 0.02597-0.1246 0.02636h{1}c-0.04786 0-0.1502"
        " 0.02094-0.2185"
        " 0.1256-0.06833-0.1046-0.1706-0.1256-0.2185-0.1256h{1}c-0.03046-3.899e-4"
        " -0.07972-0.004491-0.1246-0.02636-0.0537-0.02695-0.07418-0.05816-0.08648-0.07769-0.001562-0.002538-0.004467-0.002563-0.01091-0.002563z"
    )
    default_min_width = 0.90552
    self.buff = buff
    dx, dy = np.asarray(direction, dtype=float)[:2]
    angle = -np.arctan2(dx, dy) + np.pi
    mobject.rotate(-angle, about_point=ORIGIN)
    left = mobject.get_corner(DOWN + LEFT)
    right = mobject.get_corner(DOWN + RIGHT)
    target_width = right[0] - left[0]
    linear_section_length = max(
        0, (target_width * sharpness - default_min_width) / 2
    )
    import svgelements as se

    path = se.Path(
        path_string_template.format(linear_section_length, -linear_section_length)
    )
    super().__init__(path_obj=path, **kwargs)
    self.flip(RIGHT)
    self.stretch_to_fit_width(target_width)
    self.shift(left - self.get_corner(UP + LEFT) + self.buff * DOWN)
    for mob in (mobject, self):
        mob.rotate(angle, about_point=ORIGIN)

put_at_tip

Put a mobject at the brace's tip, beyond it.

brace.put_at_tip(mob, use_next_to=True, **kwargs)
mob

The mobject to put there.

use_next_to

Whether it goes next to the tip, on the side the brace points to (its direction rounded to one of the eight compass directions); if not, its center goes from the tip along the brace's direction, by half its width and buff.

buff

The gap between the two, in scene units (default 0.25).

aligned_edge

The edge, as a direction, along which the two line up besides the side they meet at: with the direction RIGHT and UP here, their tops line up (default ORIGIN: centered).

submobject_to_align

A part of the mobject to put beside the other in its place; the rest moves with it (default None: the whole mobject).

index_of_submobject_to_align

The index of the part of each mobject to line up: this one's part goes beside the other's (default None: the whole of each).

coor_mask

Which coordinates may change: 1 for each axis the mobject moves along, 0 for one it keeps (default (1, 1, 1)).

Source

src/manimgx/mobjects/annotations.py

def put_at_tip(
    self, mob: Mobject, use_next_to: bool = True, **kwargs: Unpack[Placement]
) -> Self:
    """Put a mobject at the brace's tip, beyond it.

    Args:
        mob: The mobject to put there.
        use_next_to: Whether it goes next to the tip, on the side the brace points
            to (its direction rounded to one of the eight compass directions); if
            not, its center goes from the tip along the brace's direction, by half
            its width and `buff`.
        **kwargs: [Placement keywords][manimgx.mobject.Placement]: `buff`, the
            gap, is 0.25 unless given.
    """
    if use_next_to:
        mob.next_to(self.get_tip(), np.round(self.get_direction()), **kwargs)
    else:
        mob.move_to(self.get_tip())
        buff = kwargs.get("buff", DEFAULT_MOBJECT_TO_MOBJECT_BUFFER)
        shift_distance = mob.width / 2.0 + buff
        mob.shift(self.get_direction() * shift_distance)
    return self

get_text

Code
import manimgx as m


class BraceGetTextExample(m.Scene):
    def construct(self) -> None:
        line = m.Line([-3, -1.5, 0], [3, 1.5, 0], color=m.ORANGE)
        normal = line.copy().rotate(m.PI / 2).get_unit_vector()
        below, side = m.Brace(line), m.Brace(line, normal)
        self.add(line, below, side)
        self.play(
            m.Write(below.get_text("Horizontal distance")),
            m.Write(side.get_tex("x - x_1")),
        )

Make a label of LaTeX text at the brace's tip, as put_at_tip puts it.

brace.get_text(*text, **kwargs)
*text

The label, in LaTeX: a string per part (see Tex).

buff

The gap between the two, in scene units (default 0.25).

aligned_edge

The edge, as a direction, along which the two line up besides the side they meet at: with the direction RIGHT and UP here, their tops line up (default ORIGIN: centered).

submobject_to_align

A part of the mobject to put beside the other in its place; the rest moves with it (default None: the whole mobject).

index_of_submobject_to_align

The index of the part of each mobject to line up: this one's part goes beside the other's (default None: the whole of each).

coor_mask

Which coordinates may change: 1 for each axis the mobject moves along, 0 for one it keeps (default (1, 1, 1)).

Returns A new Tex, at the tip; add it to the scene.

Source

src/manimgx/mobjects/annotations.py

def get_text(self, *text: str, **kwargs: Unpack[Placement]) -> Tex:
    """Make a label of LaTeX text at the brace's tip, as
    [put_at_tip][manimgx.Brace.put_at_tip] puts it.

    Args:
        *text: The label, in LaTeX: a string per part (see [Tex][manimgx.Tex]).
        **kwargs: [Placement keywords][manimgx.mobject.Placement].

    Returns:
        A new [Tex][manimgx.Tex], at the tip; add it to the scene.

    Examples:
        ```python
        import manimgx as m


        class BraceGetTextExample(m.Scene):
            def construct(self) -> None:
                line = m.Line([-3, -1.5, 0], [3, 1.5, 0], color=m.ORANGE)
                normal = line.copy().rotate(m.PI / 2).get_unit_vector()
                below, side = m.Brace(line), m.Brace(line, normal)
                self.add(line, below, side)
                self.play(
                    m.Write(below.get_text("Horizontal distance")),
                    m.Write(side.get_tex("x - x_1")),
                )
        ```
    """
    text_mob = Tex(*text)
    self.put_at_tip(text_mob, **kwargs)
    return text_mob

get_tex

Make a label of LaTeX math at the brace's tip, as put_at_tip puts it.

brace.get_tex(*tex, **kwargs)
*tex

The label, in LaTeX: a string per part (see MathTex).

buff

The gap between the two, in scene units (default 0.25).

aligned_edge

The edge, as a direction, along which the two line up besides the side they meet at: with the direction RIGHT and UP here, their tops line up (default ORIGIN: centered).

submobject_to_align

A part of the mobject to put beside the other in its place; the rest moves with it (default None: the whole mobject).

index_of_submobject_to_align

The index of the part of each mobject to line up: this one's part goes beside the other's (default None: the whole of each).

coor_mask

Which coordinates may change: 1 for each axis the mobject moves along, 0 for one it keeps (default (1, 1, 1)).

Returns A new MathTex, at the tip; add it to the scene.

Source

src/manimgx/mobjects/annotations.py

def get_tex(self, *tex: str, **kwargs: Unpack[Placement]) -> MathTex:
    """Make a label of LaTeX math at the brace's tip, as
    [put_at_tip][manimgx.Brace.put_at_tip] puts it.

    Args:
        *tex: The label, in LaTeX: a string per part (see
            [MathTex][manimgx.MathTex]).
        **kwargs: [Placement keywords][manimgx.mobject.Placement].

    Returns:
        A new [MathTex][manimgx.MathTex], at the tip; add it to the scene.
    """
    tex_mob = MathTex(*tex)
    self.put_at_tip(tex_mob, **kwargs)
    return tex_mob

get_tip

The brace's tip: the point of its middle cusp.

brace.get_tip()

Returns The point, in scene coordinates.

Source

src/manimgx/mobjects/annotations.py

def get_tip(self) -> Point3D:
    """The brace's tip: the point of its middle cusp.

    Returns:
        The point, in scene coordinates.
    """
    return self.points[28]

get_direction

The direction the brace points to: from its center to its tip.

brace.get_direction()

Returns A unit vector.

Source

src/manimgx/mobjects/annotations.py

def get_direction(  # pyright: ignore[reportIncompatibleMethodOverride]  # ty: ignore[invalid-method-override]  # CE's: a brace's direction is a vector, a path's a winding
    self,
) -> Vector3D:
    """The direction the brace points to: from its center to its tip.

    Returns:
        A unit vector.
    """
    vect = self.get_tip() - self.get_center()
    return vect / np.linalg.norm(vect)

BraceBetweenPoints

Code
import manimgx as m


class BraceBetweenPointsExample(m.Scene):
    def construct(self) -> None:
        a, b = [-3, -1, 0], [3, 2, 0]
        self.add(m.Line(a, b), m.Dot(a), m.Dot(b))
        brace = m.BraceBetweenPoints(a, b, color=m.YELLOW)
        self.play(m.GrowFromCenter(brace))

A brace spanning the segment between two points.

m.BraceBetweenPoints(point_1, point_2, direction=ORIGIN, **kwargs)
point_1

One end.

point_2

The other end.

direction

The side the brace is on, as a direction; ORIGIN (the default) for the right-hand side going from point_1 to point_2 (below, for points from left to right).

It also takes the brace keywords.

Source

src/manimgx/mobjects/annotations.py

def __init__(
    self,
    point_1: Point3DLike,
    point_2: Point3DLike,
    direction: Vector3DLike = ORIGIN,
    **kwargs: Unpack[BraceOptions],
):
    if not np.any(np.asarray(direction, dtype=float)):  # a side of the line
        line_vector = np.array(point_2, dtype=float) - np.array(
            point_1, dtype=float
        )
        direction = np.array([line_vector[1], -line_vector[0], 0])
    super().__init__(Line(point_1, point_2), direction=direction, **kwargs)

ArcBrace

Code
import manimgx as m


class ArcBraceExample(m.Scene):
    def construct(self) -> None:
        arc = m.Arc(radius=2.5, angle=2 * m.PI / 3, color=m.BLUE)
        arc.shift(1.5 * m.DOWN)
        self.add(arc)
        self.play(
            m.GrowFromCenter(m.ArcBrace(arc)),
            m.GrowFromCenter(m.ArcBrace(arc, m.LEFT, color=m.YELLOW)),
        )

A brace bent along an arc, outside it or inside.

m.ArcBrace(arc=None, direction=RIGHT, **kwargs)
arc

The arc to brace; None for one of radius 1, from -1 to 1 radian.

direction

RIGHT for the brace outside the arc, LEFT for inside.

It also takes the brace keywords.

Source

src/manimgx/mobjects/annotations.py

def __init__(
    self,
    arc: Arc | None = None,
    direction: Vector3DLike = RIGHT,
    **kwargs: Unpack[BraceOptions],
):
    if arc is None:
        arc = Arc(start_angle=-1, angle=2, radius=1)
    arc_end_angle = arc.start_angle + arc.angle
    line = Line(UP * arc.start_angle, UP * arc_end_angle)
    scale_shift = RIGHT * np.log(arc.radius)
    if arc.radius >= 1:
        line.scale(arc.radius, about_point=ORIGIN)
        super().__init__(line, direction=direction, **kwargs)
        self.scale(1 / arc.radius, about_point=ORIGIN)
    else:
        super().__init__(line, direction=direction, **kwargs)
    if arc.radius >= 0.3:
        self.shift(scale_shift)
    else:
        self.shift(RIGHT * np.log(0.3))
    self.apply_complex_function(np.exp)
    self.shift(arc.get_arc_center())

BraceLabel

Code
import manimgx as m


class BraceLabelExample(m.Scene):
    def construct(self) -> None:
        square = m.Square(side_length=3, color=m.BLUE, fill_opacity=0.5)
        side = m.BraceLabel(square, "a", font_size=72)
        diagonal = m.BraceLabel(square, r"a\sqrt{2}", m.UR, font_size=72)
        self.add(square)
        self.play(m.Write(side), m.Write(diagonal))

A brace along a side of a mobject, and a label at its tip: math unless another label class is given.

Its parts are its brace and its label.

m.BraceLabel(obj, text, brace_direction=DOWN, label_constructor=MathTex, font_size=DEFAULT_FONT_SIZE, buff=0.2, brace_config=None, **kwargs)
obj

The mobject to brace.

text

The label: a string, or several (as a MathTex's parts).

brace_direction

The side the brace is on, as a direction.

label_constructor

The label's class: MathTex, or another text class.

font_size

The label's font size.

buff

The gap between the mobject and the brace, in scene units.

brace_config

Brace keywords, over buff.

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/mobjects/annotations.py

def __init__(
    self,
    obj: Mobject,
    text: str | Sequence[str],
    brace_direction: Vector3DLike = DOWN,
    label_constructor: LabelMaker = MathTex,
    font_size: float = DEFAULT_FONT_SIZE,
    buff: float = 0.2,
    brace_config: BraceOptions | None = None,
    **kwargs: Unpack[Style],
):
    self.label_constructor = label_constructor
    super().__init__(**kwargs)
    self.brace_direction = brace_direction
    self.brace = Brace(
        obj,
        brace_direction,
        **(BraceOptions(buff=buff) | (brace_config or BraceOptions())),
    )
    """The brace, a part."""
    if isinstance(text, str):
        self.label: ManimTextLabel = self.label_constructor(
            text, font_size=font_size
        )
        """The label, at the brace's tip: a part."""
    else:
        self.label = self.label_constructor(*text, font_size=font_size, **kwargs)
    self.brace.put_at_tip(self.label)
    self.add(self.brace, self.label)

brace

The brace, a part.

label

The label, at the brace's tip: a part.

change_label

Replace the label with a new one, made of text by the label class, at the brace's tip.

brace_label.change_label(*text, **kwargs)
*text

The new label's strings.

It also takes the Typst keywords and the style keywords.

Source

src/manimgx/mobjects/annotations.py

def change_label(self, *text: str, **kwargs: Unpack[TypstOptions]) -> Self:
    """Replace the label with a new one, made of `text` by the label class, at the
    brace's tip.

    Args:
        *text: The new label's strings.
        **kwargs: [Typst keywords][manimgx.mobjects.text.TypstOptions]
            for it (at font size 48 unless given).
    """
    self.remove(self.label)
    self.label = self.label_constructor(*text, **kwargs)
    self.brace.put_at_tip(self.label)
    self.add(self.label)
    return self

BraceText

BraceTextExample
Code
import manimgx as m


class BraceTextExample(m.Scene):
    def construct(self) -> None:
        rectangle = m.Rectangle(width=6, height=3, color=m.BLUE)
        width = m.BraceText(rectangle, "width")
        height = m.BraceText(rectangle, "height", brace_direction=m.RIGHT)
        self.add(rectangle, width, height)

A brace along a side of a mobject, and a label of text at its tip: a BraceLabel whose label is a Text.

m.BraceText(obj, text, label_constructor=Text, **kwargs)
obj

The mobject to brace.

text

The label's text.

label_constructor

The label's class.

It also takes the brace label keywords.

Source

src/manimgx/mobjects/annotations.py

def __init__(
    self,
    obj: Mobject,
    text: str | Sequence[str],
    label_constructor: LabelMaker = Text,
    **kwargs: Unpack[BraceLabelOptions],
):
    super().__init__(obj, text, label_constructor=label_constructor, **kwargs)

Frames and marks

SurroundingRectangle

Code
import manimgx as m


class SurroundingRectangleExample(m.Scene):
    def construct(self) -> None:
        formula = m.MathTex(r"e^{i\pi} + 1 = 0", font_size=96)
        words = m.Text("Euler's identity").next_to(formula, m.DOWN, buff=1)
        self.add(formula, words)
        self.play(
            m.Create(m.SurroundingRectangle(formula, buff=0.3)),
            m.Create(
                m.SurroundingRectangle(words, corner_radius=0.2, color=m.BLUE)
            ),
        )

A rectangle around mobjects: around their bounding box, all of them together, with a margin; bright yellow (PURE_YELLOW) unless styled.

It is sized and placed when it is made, and does not follow the mobjects afterwards.

m.SurroundingRectangle(*mobjects, buff=SMALL_BUFF, corner_radius=0.0, **kwargs)
*mobjects

The mobjects to surround.

buff

The margin around them, in scene units: one for all sides, or (horizontal, vertical).

corner_radius

The radius of its corners, in scene units: 0 for square corners.

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/mobjects/annotations.py

def __init__(
    self,
    *mobjects: Mobject,
    buff: float | tuple[float, float] = SMALL_BUFF,
    corner_radius: float = 0.0,
    **kwargs: Unpack[Style],
) -> None:
    if not all(isinstance(mob, Mobject) for mob in mobjects):
        raise TypeError(
            "Expected all inputs for parameter mobjects to be a Mobjects"
        )
    if isinstance(buff, tuple):
        buff_x = buff[0]
        buff_y = buff[1]
    else:
        buff_x = buff_y = buff
    box = _family_box(_family(mobjects))
    if box is None:
        box = np.zeros((2, 3))
    super().__init__(
        width=float(box[1, 0] - box[0, 0]) + 2 * buff_x,
        height=float(box[1, 1] - box[0, 1]) + 2 * buff_y,
        corner_radius=corner_radius,
        **kwargs,
    )
    self.buff = buff
    self.move_to((box[0] + box[1]) / 2)

BackgroundRectangle

BackgroundRectangleExample
Code
import manimgx as m


class BackgroundRectangleExample(m.Scene):
    def construct(self) -> None:
        bare = m.Text("on the grid", font_size=60).shift(3.5 * m.LEFT)
        backed = m.Text("on a background", font_size=60).shift(3.2 * m.RIGHT)
        background = m.BackgroundRectangle(backed, buff=0.2)
        self.add(m.NumberPlane(), bare, background, backed)

A rectangle behind mobjects, in the background's color and three quarters opaque, so they stand out from what lies behind them; without an outline.

Its color is the scene's background color when it is made, unless given. It goes behind the mobjects: add it to the scene before them.

m.BackgroundRectangle(*mobjects, buff=0, corner_radius=0.0, **kwargs)
*mobjects

The mobjects to go behind.

buff

The margin around them, in scene units: one for all sides, or (horizontal, vertical).

corner_radius

The radius of its corners, in scene units: 0 for square corners.

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/mobjects/annotations.py

def __init__(
    self,
    *mobjects: Mobject,
    buff: float | tuple[float, float] = 0,
    corner_radius: float = 0.0,
    **kwargs: Unpack[Style],
) -> None:
    if kwargs.get("color") is None:  # not given (None too): the scene's, when made
        kwargs["color"] = config.background_color
    super().__init__(*mobjects, buff=buff, corner_radius=corner_radius, **kwargs)
    self.original_fill_opacity: float = self.fill_opacity

FrameOptions

The keywords of a rectangle made around a mobject, as a SurroundingRectangle or a BackgroundRectangle is: its margin and its corners, with the style keywords (for the classes that pass them on).

buff

The margin around the mobject, in scene units: one for all sides, or (horizontal, vertical) (default 0.1 around a surrounding rectangle, 0 behind a background rectangle).

corner_radius

The radius of the rectangle's corners, in scene units (default 0: square corners).

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.

buff

The margin around the mobject, in scene units: one for all sides, or (horizontal, vertical) (default 0.1 around a surrounding rectangle, 0 behind a background rectangle).

corner_radius

The radius of the rectangle's corners, in scene units (default 0: square corners).

Underline

Code
import manimgx as m


class UnderlineExample(m.Scene):
    def construct(self) -> None:
        word = m.Text("important", font_size=120)
        self.add(word)
        self.play(m.Create(m.Underline(word, buff=0.2, color=m.YELLOW)))

A line under a mobject: as wide as it, buff below it; white unless styled.

It is sized and placed when it is made, and does not follow the mobject afterwards.

m.Underline(mobject, buff=SMALL_BUFF, **kwargs)
mobject

The mobject to underline.

buff

The gap between the mobject and the line, in scene units.

path_arc

The angle the line bends through, in radians: 0 for straight; otherwise it is an arc from its start to its end, turning counterclockwise if positive (bending right on its way), clockwise if negative (default 0).

color

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

tip_length

The length of the tips add_tip makes, in scene units (default 0.35; an Arrow's may be shorter).

normal_vector

The normal of the plane the path lies in (default OUT). Accepted for Manim compatibility; ignored and not retained.

tip_style

Style keywords for the tips the path makes (default None: none). A tip's fill_color and stroke_color are the path's color unless given here.

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.

Source

src/manimgx/mobjects/annotations.py

def __init__(
    self, mobject: Mobject, buff: float = SMALL_BUFF, **kwargs: Unpack[Arced]
) -> None:
    super().__init__(LEFT, RIGHT, buff=buff, **kwargs)
    self.match_width(mobject)
    self.next_to(mobject, DOWN, buff=self.buff)

Cross

Code
import manimgx as m


class CrossExample(m.Scene):
    def construct(self) -> None:
        wrong = m.MathTex("2 + 2 = 5", font_size=96).shift(2 * m.RIGHT)
        self.add(m.Cross().shift(4 * m.LEFT), wrong)
        self.play(m.Create(m.Cross(wrong, scale_factor=1.2, color=m.YELLOW)))

A cross, an X: two lines from corner to corner of a mobject's bounding box, or of a square 2 on a side at the origin; red, 6 wide, unless styled.

m.Cross(mobject=None, stroke_color=RED, stroke_width=6.0, scale_factor=1.0, color=None, **kwargs)
mobject

The mobject to cross out: the cross is stretched over its bounding box; None for none.

stroke_color

The color of its lines.

stroke_width

The width of its lines, in hundredths of a scene unit.

scale_factor

How much larger than the bounding box (or the square) it is, about its center.

color

The color of its lines, in place of stroke_color; None to use that.

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/mobjects/annotations.py

def __init__(
    self,
    mobject: Mobject | None = None,
    stroke_color: ParsableManimColor = RED,
    stroke_width: float = 6.0,
    scale_factor: float = 1.0,
    color: ParsableManimColor | None = None,
    **kwargs: Unpack[Look],
) -> None:
    super().__init__(
        Line(UP + LEFT, DOWN + RIGHT), Line(UP + RIGHT, DOWN + LEFT), **kwargs
    )
    if mobject is not None:
        self.replace(mobject, stretch=True)
    self.scale(scale_factor)
    self.set_stroke(
        color=stroke_color if color is None else color, width=stroke_width
    )

AnnotationDot

AnnotationDotExample
Code
import manimgx as m


class AnnotationDotExample(m.Scene):
    def construct(self) -> None:
        arc = m.Arc(radius=3, angle=m.PI, color=m.GREY).shift(1.5 * m.DOWN)
        start = m.AnnotationDot(point=arc.get_start())
        end = m.AnnotationDot(point=arc.get_end())
        top = m.AnnotationDot(
            0.25, point=arc.get_top(), fill_color=m.YELLOW, stroke_color=m.RED
        )
        self.add(arc, start, end, top)

A dot to mark a point with: a little larger than a Dot, blue with a thick white outline unless styled.

Its colors are its fill_color and its stroke_color, which color does not change.

m.AnnotationDot(radius=DEFAULT_DOT_RADIUS * 1.3, *, point=ORIGIN, **kwargs)
radius

Its radius, in scene units (default 0.104, 1.3 times a dot's).

point

Where its center goes.

color

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

tip_length

The length of the tips add_tip makes, in scene units (default 0.35; an Arrow's may be shorter).

normal_vector

The normal of the plane the path lies in (default OUT). Accepted for Manim compatibility; ignored and not retained.

tip_style

Style keywords for the tips the path makes (default None: none). A tip's fill_color and stroke_color are the path's color unless given here.

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 tip keywords.

Source

src/manimgx/mobjects/shapes.py

def __init__(
    self,
    radius: float = DEFAULT_DOT_RADIUS * 1.3,
    *,
    point: Point3DLike = ORIGIN,
    **kwargs: Unpack[Tipped],
) -> None:
    super().__init__(point=point, radius=radius, **kwargs)

Labels

Label

LabelExample
Code
import manimgx as m


class LabelExample(m.Scene):
    def construct(self) -> None:
        plain = m.Label("x^2 + y^2 = r^2")
        styled = m.Label(
            m.Text("a label", color=m.YELLOW),
            box_config={"color": m.BLUE, "buff": 0.2},
            frame_config={"color": m.YELLOW, "stroke_width": 4, "buff": 0.2},
        )
        self.add(m.VGroup(plain, styled).arrange(m.DOWN, buff=1).scale(2))

A label on a background, in a frame: text or math, over an opaque rectangle in the background's color, inside a thin white outline.

A string is typeset as math, white, at font size 48 (see MathTex); a mobject of text or math is used as it is. Its parts are its submobjects, in drawing order: its background_rect, its rendered_label and its frame.

m.Label(label, label_config=None, box_config=None, frame_config=None, **kwargs)
label

The label: a string, typeset as math, or a text or math mobject.

label_config

MathTex keywords for a string label, over white at font size 48.

box_config

Surrounding rectangle keywords for the background, over a margin of 0.05 and an opaque fill (see BackgroundRectangle).

frame_config

Surrounding rectangle keywords for the frame, over white, a margin of 0.05 and an outline 0.5 wide.

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/mobjects/annotations.py

def __init__(
    self,
    label: str | ManimTextLabel,
    label_config: MathTexOptions | None = None,
    box_config: FrameOptions | None = None,
    frame_config: FrameOptions | None = None,
    **kwargs: Unpack[Style],
) -> None:
    super().__init__(**kwargs)
    label_style = MathTexOptions(color=WHITE, font_size=DEFAULT_FONT_SIZE) | (
        label_config or MathTexOptions()
    )
    box_style = FrameOptions(buff=0.05, fill_opacity=1, stroke_width=0.5) | (
        box_config or FrameOptions()
    )
    frame_style = FrameOptions(color=WHITE, buff=0.05, stroke_width=0.5) | (
        frame_config or FrameOptions()
    )
    if isinstance(label, str):
        self.rendered_label: ManimTextLabel = MathTex(label, **label_style)
        """The label's text or math, a submobject."""
    elif isinstance(label, Typst):
        self.rendered_label = label
    else:
        raise TypeError(
            "Unsupported label type. Must be MathTex, Tex, Text or Typst."
        )
    self.background_rect = BackgroundRectangle(self.rendered_label, **box_style)
    """The rectangle behind the label, a submobject."""
    self.frame = SurroundingRectangle(self.rendered_label, **frame_style)
    """The outline around the label, a submobject."""
    self.add(self.background_rect, self.rendered_label, self.frame)

rendered_label

The label's text or math, a submobject.

background_rect

The rectangle behind the label, a submobject.

frame

The outline around the label, a submobject.

LabeledDot

LabeledDotExample
Code
import manimgx as m


class LabeledDotExample(m.Scene):
    def construct(self) -> None:
        dots = m.VGroup(
            m.LabeledDot("A"),
            m.LabeledDot("42", color=m.BLUE),
            m.LabeledDot(m.MathTex(r"\alpha"), color=m.PURPLE, radius=0.5),
            m.LabeledDot(m.Text("hi", color=m.BLACK), color=m.YELLOW),
        ).arrange(buff=1)
        self.add(dots.scale(2))

A dot with a label in its middle: a disc just large enough for the label unless given a radius; white, without an outline, unless styled.

It is made at the origin, and the label, centered on it, is its submobject.

m.LabeledDot(label, radius=None, buff=SMALL_BUFF, **kwargs)
label

The label: a string, typeset as math in black (see MathTex), or a mobject, as it is.

radius

Its radius, in scene units; None for half the diagonal of the label's bounding box, plus buff.

buff

The margin between the label's corners and the dot's edge, in scene units, when the radius fits the label.

color

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

tip_length

The length of the tips add_tip makes, in scene units (default 0.35; an Arrow's may be shorter).

normal_vector

The normal of the plane the path lies in (default OUT). Accepted for Manim compatibility; ignored and not retained.

tip_style

Style keywords for the tips the path makes (default None: none). A tip's fill_color and stroke_color are the path's color unless given here.

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 tip keywords.

Source

src/manimgx/mobjects/annotations.py

def __init__(
    self,
    label: str | Mobject,
    radius: float | None = None,
    buff: float = SMALL_BUFF,
    **kwargs: Unpack[Tipped],
) -> None:
    if isinstance(label, str):
        from manimgx.mobjects.text import MathTex

        rendered_label: Mobject = MathTex(label, color=BLACK)
    else:
        rendered_label = label
    if radius is None:
        radius = buff + float(
            np.linalg.norm([rendered_label.width, rendered_label.height]) / 2
        )
    super().__init__(radius=radius, **kwargs)
    rendered_label.move_to(self.get_center())
    self.add(rendered_label)

LabeledLine

LabeledLineExample
Code
import manimgx as m


class LabeledLineExample(m.Scene):
    def construct(self) -> None:
        a, b, c = [-4, -2, 0], [4, -2, 0], [4, 2.5, 0]
        sides = m.VGroup(
            m.LabeledLine("8", start=a, end=b, color=m.BLUE),
            m.LabeledLine("4.5", start=b, end=c, color=m.GREEN),
            m.LabeledLine("c", start=c, end=a, label_position=0.4),
        )
        self.add(sides)

A line with a label on it: a Label centered at a point label_position of the way from the line's start to its end; white unless styled.

The label is a submobject, the line's label. It is placed on the straight way between the ends, even when the line is bent.

m.LabeledLine(label, label_position=0.5, label_config=None, box_config=None, frame_config=None, *, start=LEFT, end=RIGHT, **kwargs)
label

The label: a string, typeset as math, or a text or math mobject.

label_position

Where the label goes, as a proportion of the way from the line's start (0) to its end (1).

label_config

MathTex keywords for a string label (see Label).

box_config

Surrounding rectangle keywords for the label's background.

frame_config

Surrounding rectangle keywords for the label's frame.

start

Where the line starts: a point, or a mobject (see Line).

end

Where it ends: a point, or a mobject.

It also takes the Line keywords.

Source

src/manimgx/mobjects/annotations.py

def __init__(
    self,
    label: str | ManimTextLabel,
    label_position: float = 0.5,
    label_config: MathTexOptions | None = None,
    box_config: FrameOptions | None = None,
    frame_config: FrameOptions | None = None,
    *,
    start: Point3DLike | Mobject = LEFT,
    end: Point3DLike | Mobject = RIGHT,
    **kwargs: Unpack[LineOptions],
) -> None:
    super().__init__(start, end, **kwargs)
    self.label = Label(
        label=label,
        label_config=label_config,
        box_config=box_config,
        frame_config=frame_config,
    )
    """The label, a submobject."""
    line_start, line_end = self.get_start_and_end()
    self.label.move_to(line_start + (line_end - line_start) * label_position)
    self.add(self.label)

label

The label, a submobject.

LabeledArrow

LabeledArrowExample
Code
import manimgx as m


class LabeledArrowExample(m.Scene):
    def construct(self) -> None:
        arrows = m.VGroup(
            m.LabeledArrow("F", start=4 * m.LEFT, end=4 * m.RIGHT),
            m.LabeledArrow(
                "0.5",
                label_position=0.3,
                start=3 * m.LEFT + m.DOWN,
                end=3 * m.RIGHT + 2 * m.UP,
                color=m.YELLOW,
            ),
        ).arrange(m.DOWN, buff=1)
        self.add(arrows)

An arrow with a label on it: a LabeledLine that is an Arrow, stopping 0.25 short of its ends unless given another buff; white unless styled.

m.LabeledArrow(label, label_position=0.5, label_config=None, box_config=None, frame_config=None, *, start=LEFT, end=RIGHT, **kwargs)
label

The label: a string, typeset as math, or a text or math mobject.

label_position

Where the label goes, as a proportion of the way from the arrow's start (0) to its tip's point (1).

label_config

MathTex keywords for a string label (see Label).

box_config

Surrounding rectangle keywords for the label's background.

frame_config

Surrounding rectangle keywords for the label's frame.

start

Where the arrow starts: a point, or a mobject (see Line).

end

Where it points to: a point, or a mobject.

It also takes the Line keywords.

Source

src/manimgx/mobjects/annotations.py

def __init__(
    self,
    label: str | ManimTextLabel,
    label_position: float = 0.5,
    label_config: MathTexOptions | None = None,
    box_config: FrameOptions | None = None,
    frame_config: FrameOptions | None = None,
    *,
    start: Point3DLike | Mobject = LEFT,
    end: Point3DLike | Mobject = RIGHT,
    **kwargs: Unpack[LineOptions],
) -> None:
    super().__init__(start, end, **kwargs)
    self.label = Label(
        label=label,
        label_config=label_config,
        box_config=box_config,
        frame_config=frame_config,
    )
    """The label, a submobject."""
    line_start, line_end = self.get_start_and_end()
    self.label.move_to(line_start + (line_end - line_start) * label_position)
    self.add(self.label)

LabeledPolygram

LabeledPolygramExample
Code
import manimgx as m


class LabeledPolygramExample(m.Scene):
    def construct(self) -> None:
        outline = [[-6, -3, 0], [5, -3, 0], [6, 3, 0], [0, 0.5, 0], [-5, 3, 0]]
        hole = [[0, -2, 0], [0, -0.5, 0], [4, -0.5, 0], [4, -2, 0]]
        shape = m.LabeledPolygram(outline, hole, label="P", fill_opacity=0.3)
        reach = m.Circle(shape.radius, color=m.YELLOW).move_to(shape.pole)
        self.add(shape, reach)

A polygram with a label inside it, at its pole of inaccessibility: the point inside it farthest from its edges, found to within precision; blue unless styled.

The first group of vertices is its outline, and the others are holes the label is kept out of. The label is a submobject, label; pole is where it is, and radius how far that is from the nearest edge.

m.LabeledPolygram(*vertex_groups, label, precision=0.01, label_config=None, box_config=None, frame_config=None, **kwargs)
*vertex_groups

The groups of vertices, each a closed path (see Polygram): the outline first, then its holes.

label

The label: a string, typeset as math, or a text or math mobject.

precision

Allowed error in the largest distance from the polygon's edges, in scene units. Several label positions can meet this radius tolerance.

label_config

MathTex keywords for a string label (see Label).

box_config

Surrounding rectangle keywords for the label's background.

frame_config

Surrounding rectangle keywords for the label's frame.

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/mobjects/annotations.py

def __init__(
    self,
    *vertex_groups: Point3DLike_Array,
    label: str | ManimTextLabel,
    precision: float = 0.01,
    label_config: MathTexOptions | None = None,
    box_config: FrameOptions | None = None,
    frame_config: FrameOptions | None = None,
    **kwargs: Unpack[Style],
) -> None:
    super().__init__(*vertex_groups, **kwargs)
    self.label = Label(
        label=label,
        label_config=label_config,
        box_config=box_config,
        frame_config=frame_config,
    )
    """The label, a submobject."""
    rings = []
    for group in vertex_groups:
        ring = np.asarray(group, dtype=float)
        rings.append(
            ring
            if np.array_equal(ring[0], ring[-1])
            else np.vstack([ring, ring[:1]])
        )
    cell = polylabel(rings, precision=precision)
    self.pole, self.radius = (np.pad(cell.c, (0, 1), "constant"), cell.d)
    self.label.move_to(self.pole)
    self.add(self.label)

label

The label, a submobject.

Angles

Angle

AngleExample
Code
import manimgx as m


class AngleExample(m.Scene):
    def construct(self) -> None:
        line1 = m.Line(1.2 * m.LEFT, 1.2 * m.RIGHT)
        line2 = m.Line(1.2 * m.DOWN, 1.2 * m.UP).rotate(-30 * m.DEGREES)
        angles = [
            m.Angle(line1, line2, color=m.YELLOW),
            m.Angle(line1, line2, quadrant=(-1, 1), color=m.BLUE),
            m.Angle(line1, line2, other_angle=True, color=m.GREEN),
            m.Angle(line1, line2, dot=True, color=m.RED),
        ]
        labels = ["default", "quadrant=(-1, 1)", "other_angle=True", "dot=True"]
        panels = m.VGroup()
        for angle in angles:
            panels.add(m.VGroup(line1.copy(), line2.copy(), angle))
        panels.arrange(buff=1)
        for panel, label in zip(panels, labels):
            text = m.Text(label, font_size=24).next_to(panel, m.DOWN)
            self.add(panel, text)

The mark of an angle between two lines: an arc about the point where they cross, counterclockwise from a side along the first line to a side along the second; white unless styled.

The lines are taken as infinite, so they need not reach the point where they cross. From there, quadrant picks the way each side goes along its line, and other_angle turns the arc clockwise instead, marking the rest of the full turn: together they pick the angle marked, which may be more than half a turn. With elbow, the mark is two segments instead, making a corner between the two sides, as a right angle is marked. Parallel lines in the plane of the screen make an empty mark, of value 0.

m.Angle(line1, line2, radius=None, quadrant=(1, 1), other_angle=False, dot=False, dot_radius=None, dot_distance=0.55, dot_color=WHITE, elbow=False, **kwargs)
line1

The line the angle is measured from.

line2

The line it is measured to.

radius

The arc's radius, or the elbow's side, in scene units; None for 0.4, or for short lines two thirds of the distance from the crossing to the nearer of the line ends the sides point to, when that is less than 0.6.

quadrant

Which way each side goes from the crossing: a sign for each line, line1's first; 1 along the line's direction (from its start toward its end), -1 back toward its start.

other_angle

Whether the arc runs clockwise from the first side to the second instead, marking the rest of the full turn.

dot

Whether to put a dot inside the arc (an elbow has none).

dot_radius

The dot's radius, in scene units; None for a tenth of the arc's radius.

dot_distance

How far the dot is from the crossing, as a fraction of the arc's radius.

dot_color

The dot's color.

elbow

Whether to mark the angle with an elbow instead of an arc.

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/mobjects/shapes.py

def __init__(
    self,
    line1: Line,
    line2: Line,
    radius: float | None = None,
    quadrant: AngleQuadrant = (1, 1),
    other_angle: bool = False,
    dot: bool = False,
    dot_radius: float | None = None,
    dot_distance: float = 0.55,
    dot_color: ParsableManimColor = WHITE,
    elbow: bool = False,
    **kwargs: Unpack[Style],
) -> None:
    super().__init__(**kwargs)
    self.lines = (line1, line2)
    self.quadrant = quadrant
    self.dot_distance = dot_distance
    self.elbow = elbow
    try:
        inter = line_intersection(
            [line1.get_start(), line1.get_end()],
            [line2.get_start(), line2.get_end()],
        )
    except ValueError:
        lines_are_in_xy_plane = all(
            point[2] == 0
            for line in (line1, line2)
            for point in (line.get_start(), line.get_end())
        )
        directions_are_parallel = (
            np.cross(line1.get_vector(), line2.get_vector())[2] == 0
        )
        if not (lines_are_in_xy_plane and directions_are_parallel):
            raise
        self.angle_value = 0.0
        return
    if radius is None:
        if quadrant[0] == 1:
            dist_1 = np.linalg.norm(line1.get_end() - inter)
        else:
            dist_1 = np.linalg.norm(line1.get_start() - inter)
        if quadrant[1] == 1:
            dist_2 = np.linalg.norm(line2.get_end() - inter)
        else:
            dist_2 = np.linalg.norm(line2.get_start() - inter)
        radius = (
            float(2 / 3 * min(dist_1, dist_2)) if min(dist_1, dist_2) < 0.6 else 0.4
        )
    else:
        self.radius = radius
    anchor_angle_1 = inter + quadrant[0] * radius * line1.get_unit_vector()
    anchor_angle_2 = inter + quadrant[1] * radius * line2.get_unit_vector()
    if elbow:
        anchor_middle = (
            inter
            + quadrant[0] * radius * line1.get_unit_vector()
            + quadrant[1] * radius * line2.get_unit_vector()
        )
        angle_mobject: VMobject = Elbow(**kwargs)
        angle_mobject.set_points_as_corners(
            np.array([anchor_angle_1, anchor_middle, anchor_angle_2])
        )
    else:
        angle_1 = angle_of_vector(anchor_angle_1 - inter)
        angle_2 = angle_of_vector(anchor_angle_2 - inter)
        if not other_angle:
            start_angle = angle_1
            if angle_2 > angle_1:
                angle_fin = angle_2 - angle_1
            else:
                angle_fin = 2 * np.pi - (angle_1 - angle_2)
        else:
            start_angle = angle_1
            if angle_2 < angle_1:
                angle_fin = -angle_1 + angle_2
            else:
                angle_fin = -2 * np.pi + (angle_2 - angle_1)
        self.angle_value = angle_fin
        angle_mobject = Arc(
            radius=radius,
            angle=self.angle_value,
            start_angle=start_angle,
            arc_center=inter,
            **kwargs,
        )
        if dot:
            if dot_radius is None:
                dot_radius = radius / 10
            else:
                self.dot_radius = dot_radius
            right_dot = Dot(ORIGIN, radius=dot_radius, color=dot_color)
            dot_anchor = (
                inter
                + (angle_mobject.get_center() - inter)
                / np.linalg.norm(angle_mobject.get_center() - inter)
                * radius
                * dot_distance
            )
            right_dot.move_to(dot_anchor)
            self.add(right_dot)
    self.set_points(angle_mobject.points)

get_lines

The two lines the angle is between.

angle.get_lines()

Returns A new group of the two lines, line1 first.

Source

src/manimgx/mobjects/shapes.py

def get_lines(self) -> VGroup:
    """The two lines the angle is between.

    Returns:
        A new group of the two lines, `line1` first.
    """
    return VGroup(*self.lines)

get_value

The size of the angle marked: counterclockwise from its first side to its second, or clockwise, and negative, with other_angle.

An angle marked with an elbow has no value: asking for it raises an exception.

angle.get_value(degrees=False)
degrees

Whether to give it in degrees instead of radians.

Returns The angle, in radians (or degrees), from -TAU to TAU.

Source

src/manimgx/mobjects/shapes.py

def get_value(self, degrees: bool = False) -> float:
    """The size of the angle marked: counterclockwise from its first side to its
    second, or clockwise, and negative, with `other_angle`.

    An angle marked with an elbow has no value: asking for it raises an exception.

    Args:
        degrees: Whether to give it in degrees instead of radians.

    Returns:
        The angle, in radians (or degrees), from -TAU to TAU.
    """
    return self.angle_value / DEGREES if degrees else self.angle_value

from_three_points

AngleFromThreePointsExample
Code
import manimgx as m


class AngleFromThreePointsExample(m.Scene):
    def construct(self) -> None:
        a, b, c = [-4, -2, 0], [3, -2, 0], [-1, 2.5, 0]
        angles = m.VGroup(
            m.Angle.from_three_points(b, a, c, radius=0.8, color=m.YELLOW),
            m.Angle.from_three_points(c, b, a, radius=0.8, color=m.BLUE),
            m.Angle.from_three_points(a, c, b, radius=0.8, color=m.GREEN),
        )
        self.add(m.Polygon(a, b, c, color=m.WHITE), angles)

The mark of the angle ABC: at B, from the line toward A counterclockwise to the line toward C.

Angle.from_three_points(A, B, C, **kwargs)
A

A point on the first side.

B

The vertex.

C

A point on the second side.

It also takes the Angle keywords.

Returns A new angle.

Source

src/manimgx/mobjects/shapes.py

@staticmethod
def from_three_points(
    A: Point3DLike, B: Point3DLike, C: Point3DLike, **kwargs: Unpack[AngleOptions]
) -> Angle:
    """The mark of the angle ABC: at `B`, from the line toward `A` counterclockwise
    to the line toward `C`.

    Args:
        A: A point on the first side.
        B: The vertex.
        C: A point on the second side.
        **kwargs: [Angle keywords][manimgx.mobjects.shapes.AngleOptions].

    Returns:
        A new angle.

    Examples:
        ```python
        import manimgx as m


        class AngleFromThreePointsExample(m.Scene):
            def construct(self) -> None:
                a, b, c = [-4, -2, 0], [3, -2, 0], [-1, 2.5, 0]
                angles = m.VGroup(
                    m.Angle.from_three_points(b, a, c, radius=0.8, color=m.YELLOW),
                    m.Angle.from_three_points(c, b, a, radius=0.8, color=m.BLUE),
                    m.Angle.from_three_points(a, c, b, radius=0.8, color=m.GREEN),
                )
                self.add(m.Polygon(a, b, c, color=m.WHITE), angles)
        ```
    """
    return Angle(Line(B, A), Line(B, C), **kwargs)

RightAngle

RightAngleExample
Code
import manimgx as m


class RightAngleExample(m.Scene):
    def construct(self) -> None:
        a, b, c = [-6, -2, 0], [-1, -2, 0], [-6, 2, 0]
        triangle = m.Polygon(a, b, c, color=m.BLUE)
        corner = m.RightAngle(m.Line(a, b), m.Line(a, c), color=m.YELLOW)
        line1 = m.Line([1, -2, 0], [6, 3, 0])
        line2 = m.Line([1, 3, 0], [6, -2, 0])
        marks = m.VGroup(
            m.RightAngle(line1, line2),
            m.RightAngle(line1, line2, length=0.7, quadrant=(-1, -1)),
        ).set_color(m.GREEN)
        self.add(triangle, corner, line1, line2, marks)

The mark of a right angle between two lines: an Angle marked with an elbow; white unless styled.

The lines need not be perpendicular: the elbow is then a corner of a parallelogram.

m.RightAngle(line1, line2, length=None, **kwargs)
line1

The first line.

line2

The second line.

length

The length of the elbow's sides, in scene units; None for 0.4, or less for short lines (see Angle).

It also takes the Angle keywords.

Source

src/manimgx/mobjects/shapes.py

def __init__(
    self,
    line1: Line,
    line2: Line,
    length: float | None = None,
    **kwargs: Unpack[AngleShape],
) -> None:
    super().__init__(line1, line2, radius=length, elbow=True, **kwargs)

Elbow

ElbowExample
Code
import manimgx as m


class ElbowExample(m.Scene):
    def construct(self) -> None:
        elbows = m.VGroup(
            m.Elbow(),
            m.Elbow(width=1.5, color=m.BLUE),
            m.Elbow(width=2, angle=5 * m.PI / 4, color=m.YELLOW),
        ).arrange(buff=1.5)
        self.add(elbows)

The mark of a right angle: two segments width long meeting at a square corner; white unless styled.

Made at the origin, it marks the right angle between the positive x and y axes: from (0, width) across to its corner at (width, width), and down to (width, 0); angle turns it about the origin. To mark the angle between two lines, see RightAngle.

m.Elbow(width=0.2, angle=0, **kwargs)
width

The length of each segment, in scene units.

angle

The angle it is turned through about the origin, in radians, counterclockwise.

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/mobjects/shapes.py

def __init__(
    self, width: float = 0.2, angle: float = 0, **kwargs: Unpack[Style]
) -> None:
    self.angle = angle
    super().__init__(**kwargs)
    self.set_points_as_corners(np.array([UP, UP + RIGHT, RIGHT]))
    self.scale_to_fit_width(width, about_point=ORIGIN)
    self.rotate(self.angle, about_point=ORIGIN)