Size and angle¶
The film's code
import manimgx as m
class SizeAndAngleHero(m.Scene):
def construct(self) -> None:
shapes = m.VGroup(
*[
m.Square(side_length=1.6, color=m.BLUE, fill_opacity=0.5)
for _ in range(4)
]
)
shapes.arrange(buff=1.2)
names = m.VGroup(
m.Text("scale(1.4)", font="monospace", font_size=30),
m.Text("rotate(PI / 4)", font="monospace", font_size=30),
m.Text("stretch(1.6, 0)", font="monospace", font_size=30),
m.Text("flip()", font="monospace", font_size=30),
)
for shape, name in zip(shapes, names, strict=True):
name.next_to(shape, m.DOWN, buff=1.1)
marker = m.Dot(color=m.YELLOW).move_to(shapes[3].get_corner(m.UR))
shapes[3].add(marker)
self.add(shapes, names)
self.play(
shapes[0].animate.scale(1.4),
shapes[1].animate.rotate(m.PI / 4),
shapes[2].animate.stretch(1.6, 0),
shapes[3].animate.flip(),
run_time=2,
)
self.wait()
A mobject's size is its bounding box's: its width and its
height. Most shapes take their size when you make them (a
circle its radius, a text its font_size); these methods change it later, about the
mobject's center unless you give another point.
An angle is in radians: a whole turn is m.TAU, half a turn m.PI, and 30 * m.DEGREES
is 30 degrees. A positive angle turns counterclockwise.
Size¶
width ¶
The mobject's width, in scene units: its bounding box's extent along x, from the leftmost of what it draws to the rightmost. Set it to scale the mobject to that width, in proportion, about its center.
Source
src/manimgx/mobject.py
height ¶
The mobject's height, in scene units: its bounding box's extent along y, from the lowest of what it draws to the highest. Set it to scale the mobject to that height, in proportion, about its center.
Source
src/manimgx/mobject.py
scale ¶
Code
import manimgx as m
class MobjectScaleExample(m.Scene):
def construct(self) -> None:
a = m.Square(color=m.BLUE, fill_opacity=0.5)
b, c = a.copy(), a.copy()
m.VGroup(a, b, c).arrange(buff=2.5)
for square, text in zip(
(a, b, c), ("scale(2)", "about_edge=DL", "[0.5, 1.5, 1]")
):
self.add(m.Text(text, font_size=32).next_to(square, m.DOWN, 2))
self.add(a, b, c)
self.play(
a.animate.scale(2),
b.animate.scale(2, about_edge=m.DL),
c.animate.scale([0.5, 1.5, 1]),
)
Scale the mobject and its whole family about a point: by one factor, or by one per axis.
Stroke widths stay as they are, unless scale_stroke.
scale_factorThe factor: 2 doubles the mobject's size, 0.5 halves it, and a negative factor also reflects it through the point; or its factors along x, y and z.
scale_strokeWhether stroke widths scale too, by the factor (for factors per axis, the geometric mean of the sizes of x's and y's).
about_pointThe point that stays fixed; None: see
about_edge.about_edgeThe point of the mobject's bounding box that stays fixed, named by a direction (DL for its bottom left corner); None for its center.
Source
src/manimgx/mobject.py
1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 | |
scale_to_fit_width ¶
Scale the mobject in proportion to a width.
widthThe width, in scene units.
about_pointThe point that stays fixed, in scene coordinates; it takes precedence over
about_edge.about_edgeThe point of the mobject's bounding box that stays fixed, named by a direction: UP for the middle of its top edge, UR for its top right corner, ORIGIN for its center.
Source
src/manimgx/mobject.py
scale_to_fit_height ¶
Scale the mobject in proportion to a height.
heightThe height, in scene units.
about_pointThe point that stays fixed, in scene coordinates; it takes precedence over
about_edge.about_edgeThe point of the mobject's bounding box that stays fixed, named by a direction: UP for the middle of its top edge, UR for its top right corner, ORIGIN for its center.
Source
src/manimgx/mobject.py
match_width ¶
Scale the mobject in proportion to another's width.
mobjectThe mobject to match.
about_pointThe point that stays fixed, in scene coordinates; it takes precedence over
about_edge.about_edgeThe point of the mobject's bounding box that stays fixed, named by a direction: UP for the middle of its top edge, UR for its top right corner, ORIGIN for its center.
Source
src/manimgx/mobject.py
match_height ¶
Scale the mobject in proportion to another's height.
mobjectThe mobject to match.
about_pointThe point that stays fixed, in scene coordinates; it takes precedence over
about_edge.about_edgeThe point of the mobject's bounding box that stays fixed, named by a direction: UP for the middle of its top edge, UR for its top right corner, ORIGIN for its center.
Source
src/manimgx/mobject.py
stretch ¶
Stretch the mobject and its whole family along one axis: scale that coordinate of every point, about a point, and keep the others.
Stroke widths stay as they are.
factorThe factor: 2 makes the mobject twice as long along the axis.
dimThe axis: 0 for x (its width), 1 for y (its height), 2 for z.
about_pointThe point that stays fixed; None: see
about_edge.about_edgeThe point of the mobject's bounding box that stays fixed, named by a direction (DOWN for the middle of its bottom edge); None for its center.
Source
src/manimgx/mobject.py
stretch_to_fit_width ¶
Stretch the mobject horizontally to a width; its height stays.
widthThe width, in scene units.
about_pointThe point that stays fixed, in scene coordinates; it takes precedence over
about_edge.about_edgeThe point of the mobject's bounding box that stays fixed, named by a direction: UP for the middle of its top edge, UR for its top right corner, ORIGIN for its center.
Source
src/manimgx/mobject.py
stretch_to_fit_height ¶
Stretch the mobject vertically to a height; its width stays.
heightThe height, in scene units.
about_pointThe point that stays fixed, in scene coordinates; it takes precedence over
about_edge.about_edgeThe point of the mobject's bounding box that stays fixed, named by a direction: UP for the middle of its top edge, UR for its top right corner, ORIGIN for its center.
Source
src/manimgx/mobject.py
replace ¶
Put the mobject in another's place: scaled to its extent along one axis (or stretched to its width and height), and centered on it.
The other mobject stays where it is.
mobjectThe mobject whose place it takes.
dim_to_matchThe axis whose extent it takes, in proportion: 0 for x (the width), 1 for y (the height), 2 for z.
stretchWhether to stretch it to the other's width and height instead.
Source
src/manimgx/mobject.py
Angle¶
m.PI ¶
π: half a turn, in radians.
m.TAU ¶
τ = 2π: a whole turn, in radians.
m.DEGREES ¶
One degree, in radians: 30 * DEGREES is a twelfth of a turn.
rotate ¶
Code
import manimgx as m
class MobjectRotateExample(m.Scene):
def construct(self) -> None:
a = m.Square(side_length=2.5, color=m.BLUE, fill_opacity=0.5)
b = m.Square(side_length=2.5, color=m.YELLOW, fill_opacity=0.5)
m.VGroup(a, b).arrange(buff=4)
pivot = m.Dot(b.get_corner(m.DL), radius=0.12, color=m.RED)
self.add(a, b, pivot)
self.play(
a.animate.rotate(m.PI / 4),
b.animate.rotate(m.PI / 2, about_edge=m.DL),
)
Rotate the mobject and its whole family by an angle, about an axis through a point.
Its sheen direction turns with it. Through animate, the mobject turns rigidly through the whole angle.
mobject.rotate(angle, axis=OUT, *, about_point=None, about_edge=None)
angleThe angle, in radians: counterclockwise as seen from where
axispoints (on the screen, for the default axis).axisThe axis's direction (default OUT, out of the screen: a turn in the plane).
about_pointThe point the axis goes through; None: see
about_edge.about_edgeThe point of the mobject's bounding box the axis goes through, named by a direction (DL for its bottom left corner); None for its center.
Source
src/manimgx/mobject.py
flip ¶
Flip the mobject and its whole family over: turn it half around an axis through a point, which mirrors it across that axis.
About the default UP axis, it is mirrored left to right; about RIGHT, upside down. Through animate, it turns over, through space.
mobject.flip(axis=UP, *, about_point=None, about_edge=None)
axisThe axis's direction (default UP).
about_pointThe point the axis goes through; None: see
about_edge.about_edgeThe point of the mobject's bounding box the axis goes through, named by a direction; None for its center.
Source
src/manimgx/mobject.py
rotation_matrix ¶
The matrix of a rotation about an axis through the origin.
Raises ValueError for a zero axis: a turn about no axis is no turn at all.
angleThe angle, in radians, counterclockwise as seen from the tip of
axis.axisThe axis's direction (its length does not matter).
Returns The 3×3 rotation matrix.
Source
src/manimgx/drawing/geometry.py
Any change¶
put_start_and_end_on ¶
Move, turn and scale the mobject so its first point is at start and its
last at end; its shape stays, scaled in proportion.
A mobject whose first and last points coincide is only moved.
startWhere its first point goes.
endWhere its last point goes.
Source
src/manimgx/mobject.py
apply_matrix ¶
Code
import manimgx as m
class MobjectApplyMatrixExample(m.Scene):
def construct(self) -> None:
grid = m.NumberPlane()
square = m.Square(color=m.YELLOW, fill_opacity=0.5).shift(m.UR)
shear = [[1, 1], [0, 1]]
self.add(grid, square)
self.play(
grid.animate.apply_matrix(shear),
square.animate.apply_matrix(shear),
run_time=2,
)
Transform the mobject and its whole family by a matrix: each point, taken relative to a fixed point, is multiplied by it.
matrixA 3 × 3 matrix, or a smaller one (2 × 2) that acts on the first coordinates and keeps the rest.
about_pointThe point that stays fixed; with neither this nor
about_edge, the origin.about_edgeThe point of the mobject's bounding box that stays fixed, named by a direction.
Source
src/manimgx/mobject.py
apply_function ¶
Code
import numpy as np
import manimgx as m
def wave(p: np.ndarray) -> np.ndarray:
return p + 0.5 * np.array([np.sin(p[1]), np.sin(p[0]), 0])
class MobjectApplyFunctionExample(m.Scene):
def construct(self) -> None:
grid = m.NumberPlane()
grid.prepare_for_nonlinear_transform()
self.add(grid)
self.play(grid.animate.apply_function(wave), run_time=2)
Move the mobject's whole family through a function, about a point: each drawn member becomes its image under the function.
A path's curves are mapped to the curves of their image. Each curve is mapped to the curve through the images of its ends, along the images of its directions there; where one strays from the true image halfway along it by more than 0.001 scene units (a quarter of a pixel at 4K), every curve of the path is cut into 2, 4, 8, … equal pieces (at most 256 each), and the pieces are mapped instead. Any other kind maps its points. Through animate, each point of the path, cut the same way, moves straight to its image.
functionA function of a point, relative to the fixed point, that returns its new place.
about_pointThe point the function is applied about; with neither this nor
about_edge, the origin, so the function sees scene coordinates.about_edgeThe point of the mobject's bounding box it is applied about, named by a direction.
Source
src/manimgx/mobject.py
apply_complex_function ¶
Code
import manimgx as m
class MobjectApplyComplexFunctionExample(m.Scene):
def construct(self) -> None:
grid = m.ComplexPlane(x_range=(-4, 4, 0.5), y_range=(-4, 4, 0.5))
grid.prepare_for_nonlinear_transform()
self.add(grid)
self.play(
grid.animate.apply_complex_function(lambda z: z**2 / 4),
run_time=2,
)
Move the mobject's whole family through a function of a complex number: the
point (x, y, z) is x + iy, and goes where function sends it, keeping its z.
A path's curves are mapped as apply_function maps them.
functionA function of a complex number, returning one.
about_pointThe point that stays fixed, in scene coordinates; it takes precedence over
about_edge.about_edgeThe point of the mobject's bounding box that stays fixed, named by a direction: UP for the middle of its top edge, UR for its top right corner, ORIGIN for its center.
Source
src/manimgx/mobject.py
set ¶
Set attributes of the mobject by name: its properties, such as width,
height or color (or a text's font_size), or any other attribute.
Through animate it animates the change:
mobject.animate.set(width=4).
The attributes' names, with their values.
Source
src/manimgx/mobject.py