Positions¶
The film's code
import manimgx as m
class PositionsHero(m.Scene):
def construct(self) -> None:
plane = m.NumberPlane(
background_line_style={"stroke_color": m.GREY_D, "stroke_width": 1},
axis_config={"stroke_color": m.GREY_B, "stroke_width": 2},
)
self.add(plane)
names = ["ORIGIN", "UP", "DOWN", "LEFT", "RIGHT", "UL", "UR", "DL", "DR"]
points = [m.ORIGIN, m.UP, m.DOWN, m.LEFT, m.RIGHT, m.UL, m.UR, m.DL, m.DR]
dots = m.VGroup()
labels = m.VGroup()
for name, point in zip(names, points, strict=True):
dot = m.Dot(2.5 * point, radius=0.12, color=m.YELLOW)
label = m.Text(name, font="monospace", font_size=30)
label.next_to(dot, m.DOWN, buff=0.2)
label.add_background_rectangle(opacity=1, buff=0.05)
dots.add(dot)
labels.add(label)
self.play(
m.LaggedStart(*[m.GrowFromCenter(dot) for dot in dots], lag_ratio=0.1)
)
self.play(m.FadeIn(labels))
self.wait()
Every mobject has a place in the frame. A place is a point, three numbers [x, y, z],
measured in units from the frame's center. x grows to the right, y grows upward, and z
grows out of the screen, toward the viewer. The frame's short side is 8 units: a wide
video shows y from −4 to 4, and x from about −7.1 to 7.1.
A mobject's place is its bounding box: the smallest box, along the axes, around what it
draws. Its center, its edges and its corners are points of that box. The methods below read
those points, and move the mobject so that one of them goes where you say. Each method
moves the mobject's parts with it, and gives the mobject back, so that calls chain:
m.Text("Title").scale(1.5).to_edge(m.UP).
Directions¶
The axis directions are unit vectors; the diagonals are sums of them. Multiply a direction
by a number, and add directions together, to make other points: 3 * m.RIGHT + 2 * m.UP
is [3, 2, 0].
m.ORIGIN
¶
The center of the scene: (0, 0, 0).
m.UP
¶
One unit up: (0, 1, 0).
m.DOWN
¶
One unit down: (0, −1, 0).
m.LEFT
¶
One unit left: (−1, 0, 0).
m.RIGHT
¶
One unit right: (1, 0, 0).
m.UL
¶
Up and left, toward the upper left corner: (−1, 1, 0).
m.UR
¶
Up and right, toward the upper right corner: (1, 1, 0).
m.DL
¶
Down and left, toward the lower left corner: (−1, −1, 0).
m.DR
¶
Down and right, toward the lower right corner: (1, −1, 0).
m.IN
¶
One unit into the screen, away from the viewer: (0, 0, −1).
m.OUT
¶
One unit out of the screen, toward the viewer: (0, 0, 1).
m.X_AXIS
¶
The direction of the x axis: (1, 0, 0).
m.Y_AXIS
¶
The direction of the y axis: (0, 1, 0).
m.Z_AXIS
¶
The direction of the z axis, out of the screen: (0, 0, 1).
Where a mobject is¶
Each of these reads a point of the mobject's bounding box, or one of its coordinates.
get_center
¶
The center of the mobject's bounding box.
Returns The point, in scene coordinates.
get_top
¶
The middle of the top edge of the mobject's bounding box.
Returns The point, in scene coordinates.
get_bottom
¶
The middle of the bottom edge of the mobject's bounding box.
Returns The point, in scene coordinates.
get_left
¶
The middle of the left edge of the mobject's bounding box.
Returns The point, in scene coordinates.
get_right
¶
The middle of the right edge of the mobject's bounding box.
Returns The point, in scene coordinates.
get_corner
¶
A corner of the mobject's bounding box, named by a direction (get_corner(UR)):
another name for get_critical_point.
get_critical_point
¶
A point of the mobject's bounding box, named by a direction: its center, the middle of an edge, or a corner.
Each coordinate is the box's lowest where the direction's is negative, its highest where it is positive, and its middle where it is 0: UR names the top right corner, UP the middle of the top edge, ORIGIN the center. The box is boundary_box, around what the mobject draws: a path's curves themselves, not their control points.
directionThe direction, such as UP, UR or ORIGIN.
Returns The point, in scene coordinates; the origin if the mobject has no points.
Source
src/manimgx/mobject.py
get_boundary_point
¶
The point of the mobject farthest in a direction: of the points it is drawn
through, the one farthest along direction.
Unlike get_critical_point, it is one of those points (for a path, an end of one of its curves), not a point of the mobject's bounding box.
Returns The point, in scene coordinates.
Source
src/manimgx/mobject.py
get_x
¶
The x coordinate of the mobject's center, or of an edge of its bounding box.
mobject.get_x(direction=ORIGIN)
directionLEFT for its left edge, RIGHT for its right edge; ORIGIN (default) for its center.
Source
src/manimgx/mobject.py
get_y
¶
The y coordinate of the mobject's center, or of an edge of its bounding box.
mobject.get_y(direction=ORIGIN)
directionDOWN for its bottom edge, UP for its top edge; ORIGIN (default) for its center.
Source
src/manimgx/mobject.py
get_z
¶
The z coordinate of the mobject's center, or of a face of its bounding box.
mobject.get_z(direction=ORIGIN)
directionIN for its lowest z, OUT for its highest; ORIGIN (default) for its center.
Source
src/manimgx/mobject.py
boundary_box
¶
The mobject's bounding box: the smallest box, aligned with the axes, around what its family draws.
A path is measured by its curves themselves, not by their control points (a
curve bulges past its anchors where it turns, and its handles reach past the
curve); any other kind by its points. A stroke's width is not counted. It is
the one box every measure reads: width and
height, the corners, edges and center
(get_critical_point), get_x and get_y,
alignment and layout, and the extent of a color gradient. It joins the boxes of
the family's members, so a member spans the same in whatever group holds it.
Returns A 2 × 3 array, the lowest (x, y, z) then the highest; None if the family has no points.
Source
src/manimgx/mobject.py
Move a mobject¶
move_to
¶
Code
import manimgx as m
class MobjectMoveToExample(m.Scene):
def construct(self) -> None:
dot = m.Dot([3, 1.5, 0], radius=0.15, color=m.YELLOW)
origin = m.Dot(radius=0.15, color=m.RED)
square = m.Square(color=m.BLUE, fill_opacity=0.5).shift(4 * m.LEFT)
self.add(dot, origin, square)
self.play(square.animate.move_to(dot))
self.play(square.animate.move_to(m.ORIGIN, aligned_edge=m.DL))
Move the mobject to a point, or onto another mobject: its center, or the
point of its bounding box aligned_edge names, goes there.
mobject.move_to(point_or_mobject, aligned_edge=ORIGIN, coor_mask=(1, 1, 1))
point_or_mobjectA point, in scene coordinates, or a mobject: then the point of its bounding box
aligned_edgenames (its center, by default).aligned_edgeThe point of the mobject that goes there, named by a direction: ORIGIN (default) for its center, DL for its bottom left corner.
coor_maskWhich coordinates change: 1 for each axis the mobject moves along, 0 for one it keeps (
(1, 0, 0)moves it horizontally only).
Source
src/manimgx/mobject.py
shift
¶
Move the mobject and its whole family by a vector.
*vectorsThe vector, in scene units (
2 * RIGHTmoves it two units right); several are added into one.
Source
src/manimgx/mobject.py
center
¶
set_x
¶
Move the mobject left or right so its center, or an edge of its bounding box,
is at x.
mobject.set_x(x, direction=ORIGIN)
xThe x coordinate, in scene units.
directionLEFT to place its left edge, RIGHT its right edge; ORIGIN (default) its center.
Source
src/manimgx/mobject.py
set_y
¶
Move the mobject up or down so its center, or an edge of its bounding box, is
at y.
mobject.set_y(y, direction=ORIGIN)
yThe y coordinate, in scene units.
directionDOWN to place its bottom edge, UP its top edge; ORIGIN (default) its center.
Source
src/manimgx/mobject.py
set_z
¶
Move the mobject in or out so its center, or a face of its bounding box, is
at z.
mobject.set_z(z, direction=ORIGIN)
zThe z coordinate, in scene units.
directionIN to place its lowest z, OUT its highest; ORIGIN (default) its center.
Source
src/manimgx/mobject.py
Place a mobject by another¶
A gap between two mobjects is a buff. These are its usual sizes.
m.SMALL_BUFF
¶
A small gap, in scene units: 0.1.
m.MED_SMALL_BUFF
¶
A medium-small gap, in scene units: 0.25, the default between mobjects placed next to each other.
m.MED_LARGE_BUFF
¶
A medium-large gap, in scene units: 0.5, the default between a mobject and the frame's edge.
m.LARGE_BUFF
¶
A large gap, in scene units: 1.
m.DEFAULT_MOBJECT_TO_MOBJECT_BUFFER
¶
The gap between mobjects placed next to each other by default, in scene units:
0.25 (next_to, arrange).
m.DEFAULT_MOBJECT_TO_EDGE_BUFFER
¶
The gap a mobject keeps from the frame's edge by default, in scene units: 0.5
(to_edge, to_corner).
next_to
¶

Code
import manimgx as m
class MobjectNextToExample(m.Scene):
def construct(self) -> None:
square = m.Square(side_length=3, color=m.BLUE, fill_opacity=0.5)
right = m.Text("RIGHT").next_to(square, m.RIGHT)
up = m.Text("UP, aligned LEFT").next_to(
square, m.UP, aligned_edge=m.LEFT
)
down = m.Text("DOWN, buff=1").next_to(square, m.DOWN, buff=1)
dot = m.Dot(radius=0.2, color=m.YELLOW)
dot.next_to(square, m.UL, buff=0)
self.add(square, right, up, down, dot)
Put the mobject beside another, or beside a point, buff away in a
direction.
The side of the mobject facing back along direction goes to the other's side
facing along it, buff farther on: with RIGHT, the middle of its left edge goes
buff to the right of the middle of the other's right edge. A diagonal
direction (UR) puts corner to corner.
mobject.next_to(mobject_or_point, direction=RIGHT, buff=DEFAULT_MOBJECT_TO_MOBJECT_BUFFER, aligned_edge=ORIGIN, submobject_to_align=None, index_of_submobject_to_align=None, coor_mask=(1, 1, 1))
mobject_or_pointThe mobject (its bounding box) or the point to put it beside.
directionThe side: RIGHT (default), UP, DL, …
buffThe gap, in scene units, along
direction(default 0.25).aligned_edgeThe edge along which the two line up besides the side they meet at, named by a direction: with the direction RIGHT and UP here, their tops line up (default ORIGIN: centered).
submobject_to_alignA part of the mobject to put beside the other in its place; the rest moves with it.
index_of_submobject_to_alignThe index of the part of each mobject to line up: this one's part goes beside the other's.
coor_maskWhich coordinates change: 1 for each axis the mobject moves along, 0 for one it keeps.
Source
src/manimgx/mobject.py
2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 | |
align_to
¶
Code
import manimgx as m
class MobjectAlignToExample(m.Scene):
def construct(self) -> None:
floor = m.Line(6 * m.LEFT, 6 * m.RIGHT).shift(3 * m.DOWN)
shapes = m.VGroup(
m.Circle(color=m.BLUE),
m.Square(side_length=3, color=m.GREEN),
m.Triangle(color=m.YELLOW),
m.Star(color=m.RED),
).arrange(buff=1)
self.add(floor, shapes)
self.play(*(s.animate.align_to(floor, m.DOWN) for s in shapes))
Move the mobject so a side of it lines up with another's: along each axis on
which direction is not 0, the side of its bounding box in that direction goes
where the other's is.
align_to(other, UP) puts its top at the height of the other's top, moving it
up or down only; align_to(other, UL) lines up both tops and both left sides.
With the default ORIGIN, nothing moves.
mobject.align_to(mobject_or_point, direction=ORIGIN)
mobject_or_pointThe mobject to line up with (the side of its bounding box
directionnames), or a point.directionThe side, named by a direction: UP, DL, …
Source
src/manimgx/mobject.py
match_x
¶
Move the mobject left or right to another's x: centers, or left or right edges, lined up.
mobject.match_x(mobject, direction=ORIGIN)
mobjectThe mobject to match.
directionLEFT to line up the left edges, RIGHT the right ones; ORIGIN (default) the centers.
Source
src/manimgx/mobject.py
match_y
¶
Move the mobject up or down to another's y: centers, or top or bottom edges, lined up.
mobject.match_y(mobject, direction=ORIGIN)
mobjectThe mobject to match.
directionDOWN to line up the bottom edges, UP the top ones; ORIGIN (default) the centers.
Source
src/manimgx/mobject.py
match_z
¶
Move the mobject in or out to another's z: centers, or faces, lined up.
mobject.match_z(mobject, direction=ORIGIN)
mobjectThe mobject to match.
directionIN to line up the lowest z, OUT the highest; ORIGIN (default) the centers.
Source
src/manimgx/mobject.py
Place a mobject in the frame¶
to_edge
¶

Move the mobject to an edge of the frame, buff in from it; along the edge,
it stays where it is.
The frame is the configured one, centered on the origin, wherever the camera looks.
mobject.to_edge(edge=LEFT, buff=DEFAULT_MOBJECT_TO_EDGE_BUFFER)
edgeThe edge: UP, DOWN, LEFT (default) or RIGHT.
buffThe margin between the mobject and the edge, in scene units (default 0.5).
Source
src/manimgx/mobject.py
to_corner
¶

Move the mobject into a corner of the frame, buff in from both its edges.
The frame is the configured one, centered on the origin, wherever the camera looks.
mobject.to_corner(corner=DL, buff=DEFAULT_MOBJECT_TO_EDGE_BUFFER)
cornerThe corner: UL, UR, DL (default) or DR.
buffThe margin between the mobject and each edge of the frame, in scene units (default 0.5).
Source
src/manimgx/mobject.py
shift_onto_screen
¶
Move the mobject back into the frame where it reaches past an edge, or nearer
to it than buff: to that edge, buff in (see
to_edge).
mobject.shift_onto_screen(buff=DEFAULT_MOBJECT_TO_EDGE_BUFFER)
buffThe margin to keep from the frame's edges, in scene units (default 0.5).
Source
src/manimgx/mobject.py
is_off_screen
¶
Whether the mobject is wholly outside the frame: the configured one, centered on the origin.
Returns True if its bounding box lies wholly past an edge of the frame.
Source
src/manimgx/mobject.py
Compute a point¶
Points are NumPy arrays, so NumPy computes with them. These functions do what a scene often needs.
interpolate
¶
The value a fraction of the way from one value to another: (1 − alpha)·start + alpha·end.
startThe value at 0: a number or an array.
endThe value at 1, of the same kind.
alphaHow far from
starttoend: 0 givesstart, 1end, and beyond them it goes on along the line; an array gives one value per entry.
Returns The value between.
Source
src/manimgx/drawing/geometry.py
integer_interpolate
¶
Which whole step from start toward end a fraction falls in, and how far into
it: for start 0 and end n, which of n curves, and where along it.
startThe first step's start, a whole number.
endThe last step's end, a whole number past
start.alphaHow far from
starttoend, from 0 to 1.
Returns
step +
fraction is start + (end − start)·alpha; at 1, the last step, wholly.
Source
src/manimgx/drawing/geometry.py
midpoint
¶
The point halfway between two points.
p1A point.
p2Another point.
Returns The point between them.
Source
src/manimgx/drawing/geometry.py
normalize
¶
The unit vector in a vector's direction.
vectThe vector.
Returns The vector divided by its length; the zero vector stays zero.
Source
src/manimgx/drawing/geometry.py
rotate_vector
¶
A vector rotated about an axis through the origin.
vectorThe vector; a two-dimensional one gets a z of 0.
angleThe angle, in radians, counterclockwise as seen from the tip of
axis.axisThe axis's direction.
Returns The rotated vector.
Source
src/manimgx/drawing/geometry.py
angle_of_vector
¶
The angle of a vector in the xy plane, counterclockwise from the x axis (its z is ignored).
Returns The angle, in radians, from −π to π.
Source
src/manimgx/drawing/geometry.py
angle_between_vectors
¶
The angle between two vectors.
v1A vector.
v2Another vector.
Returns The angle, in radians, from 0 to π.
Source
src/manimgx/drawing/geometry.py
line_intersection
¶
Where two lines in the xy plane cross, each line through two points (their z is ignored).
Raises an exception if the lines are parallel.
line1Two points on the first line.
line2Two points on the second line.
Returns The point, with a z of 0.
Source
src/manimgx/drawing/geometry.py
perpendicular_bisector
¶
Two points on the perpendicular bisector of a segment, in the plane perpendicular to a vector.
lineThe segment's two ends.
norm_vectorThe normal of the plane the bisector lies in.
Returns
The segment's midpoint plus and minus its direction crossed with
norm_vector; for a unit normal, each a segment's length from the midpoint.
Source
src/manimgx/drawing/geometry.py
polylabel
¶
The pole of inaccessibility of a polygon: the point inside it farthest from its edges, where a label fits best.
ringsThe polygon's rings, each closed (its first vertex repeated at its end): the outline, then any holes. Their x and y count.
precisionHow far, at most, the point found may be from the best, in its distance from the edges, in scene units.
Returns
The cell found, whose c is the point (x and y) and d its distance from the
nearest edge.
Source
src/manimgx/drawing/geometry.py
inverse_interpolate
¶
How far a value is from one value to another: the inverse of interpolate.
startThe value at 0.
endThe value at 1.
Returns The fraction, (value − start) / (end − start).
Source
src/manimgx/drawing/geometry.py