Animation engine for explanatory math videos with programmatic mathematical visualization capabilities
—
ManimGL's mathematical objects (Mobjects) are the building blocks of animations. They represent visual elements that can be positioned, styled, and animated. The library provides a comprehensive collection of geometric shapes, mathematical constructs, and specialized objects for mathematical visualization.
Foundation classes that provide core functionality for all mathematical objects.
class Mobject:
def __init__(self, **kwargs):
"""
Base class for all mathematical objects.
Parameters:
- color: Color specification
- name: str, object identifier
"""
def shift(self, vector):
"""
Move object by specified vector.
Parameters:
- vector: np.array or list, displacement vector
Returns:
Mobject (self)
"""
def move_to(self, point_or_mobject):
"""
Move object to specified position.
Parameters:
- point_or_mobject: Position or another mobject to align with
Returns:
Mobject (self)
"""
def scale(self, factor, **kwargs):
"""
Scale object by specified factor.
Parameters:
- factor: float, scaling factor
- about_point: np.array, point to scale around (default: center)
- about_edge: np.array, edge to scale around
Returns:
Mobject (self)
"""
def rotate(self, angle, axis=OUT, **kwargs):
"""
Rotate object around specified axis.
Parameters:
- angle: float, rotation angle in radians
- axis: np.array, rotation axis (default: OUT for 2D rotation)
- about_point: np.array, point to rotate around
Returns:
Mobject (self)
"""
def flip(self, axis=RIGHT):
"""
Flip object across specified axis.
Parameters:
- axis: np.array, axis to flip across
Returns:
Mobject (self)
"""
def set_color(self, color):
"""
Set object color.
Parameters:
- color: Color specification
Returns:
Mobject (self)
"""
def copy(self):
"""
Create a copy of the object.
Returns:
Mobject (copy of self)
"""
class Group(Mobject):
def __init__(self, *mobjects, **kwargs):
"""
Container for grouping multiple mobjects.
Parameters:
- mobjects: Mobject instances to group
"""
def add(self, *mobjects):
"""
Add mobjects to the group.
Parameters:
- mobjects: Mobject instances to add
Returns:
Group (self)
"""
class Point(Mobject):
def __init__(self, location=ORIGIN, **kwargs):
"""
Single point in space.
Parameters:
- location: np.array, point coordinates
"""Advanced mobjects with vectorized graphics capabilities for smooth curves and complex shapes.
class VMobject(Mobject):
def __init__(self, **kwargs):
"""
Base vectorized mobject with bezier curve support.
Parameters:
- fill_color: Interior color
- fill_opacity: float, interior opacity (0-1)
- stroke_color: Border color
- stroke_width: float, border width
- stroke_opacity: float, border opacity (0-1)
"""
def set_points(self, points):
"""
Set the bezier curve points.
Parameters:
- points: np.array, array of control points
Returns:
VMobject (self)
"""
def set_fill(self, color=None, opacity=None):
"""
Set fill properties.
Parameters:
- color: Fill color
- opacity: float, fill opacity (0-1)
Returns:
VMobject (self)
"""
def set_stroke(self, color=None, width=None, opacity=None):
"""
Set stroke properties.
Parameters:
- color: Stroke color
- width: float, stroke width
- opacity: float, stroke opacity (0-1)
Returns:
VMobject (self)
"""
class VGroup(VMobject):
def __init__(self, *vmobjects, **kwargs):
"""
Group of vectorized mobjects.
Parameters:
- vmobjects: VMobject instances to group
"""
class VectorizedPoint(VMobject):
def __init__(self, location=ORIGIN, **kwargs):
"""
Vectorized point representation.
Parameters:
- location: np.array, point coordinates
"""
class DashedVMobject(VMobject):
def __init__(self, vmobject, **kwargs):
"""
Dashed version of any VMobject.
Parameters:
- vmobject: VMobject to make dashed
- num_dashes: int, number of dash segments
- dash_length: float, length of each dash
"""Fundamental geometric shapes including lines, circles, polygons, and curves.
class Line(VMobject):
def __init__(self, start=LEFT, end=RIGHT, **kwargs):
"""
Straight line segment.
Parameters:
- start: np.array, starting point
- end: np.array, ending point
- path_arc: float, arc curvature (0 for straight line)
"""
def get_start(self):
"""Get line start point."""
def get_end(self):
"""Get line end point."""
def get_center(self):
"""Get line center point."""
def get_length(self):
"""Get line length."""
class DashedLine(Line):
def __init__(self, *args, **kwargs):
"""
Dashed line segment.
Parameters:
- dash_length: float, length of dashes
- dash_spacing: float, spacing between dashes
"""
class Arrow(Line):
def __init__(self, *args, **kwargs):
"""
Line with arrowhead.
Parameters:
- buff: float, buffer space from endpoints
- max_tip_length_to_length_ratio: float, tip size ratio
- max_stroke_width_to_length_ratio: float, stroke ratio
"""
class Vector(Arrow):
def __init__(self, direction=RIGHT, **kwargs):
"""
Vector arrow from origin.
Parameters:
- direction: np.array, vector direction and magnitude
"""
class DoubleArrow(Arrow):
def __init__(self, *args, **kwargs):
"""Line with arrowheads on both ends."""
class Arc(VMobject):
def __init__(self, start_angle=0, angle=TAU/4, **kwargs):
"""
Circular arc.
Parameters:
- start_angle: float, starting angle in radians
- angle: float, arc angle in radians
- radius: float, arc radius
- arc_center: np.array, center point
"""
class Circle(Arc):
def __init__(self, radius=None, **kwargs):
"""
Complete circle.
Parameters:
- radius: float, circle radius (default: 1.0)
- color: Circle color
"""
def get_radius(self):
"""Get circle radius."""
class Dot(Circle):
def __init__(self, point=ORIGIN, **kwargs):
"""
Point represented as small filled circle.
Parameters:
- point: np.array, dot location
- radius: float, dot size (default: 0.08)
- color: Dot color
"""
class SmallDot(Dot):
def __init__(self, point=ORIGIN, **kwargs):
"""Smaller dot with radius 0.04."""
class Ellipse(Circle):
def __init__(self, width=2, height=1, **kwargs):
"""
Elliptical shape.
Parameters:
- width: float, ellipse width
- height: float, ellipse height
"""
class Sector(Arc):
def __init__(self, **kwargs):
"""
Circular sector (pie slice).
Parameters:
- start_angle: float, sector start angle
- angle: float, sector angle
- outer_radius: float, sector radius
- inner_radius: float, inner radius (for annular sector)
"""
class Annulus(Circle):
def __init__(self, inner_radius=1, outer_radius=2, **kwargs):
"""
Ring shape (annulus).
Parameters:
- inner_radius: float, inner circle radius
- outer_radius: float, outer circle radius
"""Multi-sided shapes and complex geometric constructs.
class Polygon(VMobject):
def __init__(self, *vertices, **kwargs):
"""
Multi-sided polygon.
Parameters:
- vertices: np.array points defining polygon vertices
"""
def get_vertices(self):
"""Get polygon vertices."""
class RegularPolygon(Polygon):
def __init__(self, n=6, **kwargs):
"""
Regular polygon with n sides.
Parameters:
- n: int, number of sides
- radius: float, circumscribed radius
- start_angle: float, rotation angle
"""
class Triangle(RegularPolygon):
def __init__(self, **kwargs):
"""Equilateral triangle."""
class Rectangle(Polygon):
def __init__(self, width=4.0, height=2.0, **kwargs):
"""
Rectangle shape.
Parameters:
- width: float, rectangle width
- height: float, rectangle height
"""
def get_width(self):
"""Get rectangle width."""
def get_height(self):
"""Get rectangle height."""
class Square(Rectangle):
def __init__(self, side_length=2.0, **kwargs):
"""
Square shape.
Parameters:
- side_length: float, side length
"""
class RoundedRectangle(Rectangle):
def __init__(self, **kwargs):
"""
Rectangle with rounded corners.
Parameters:
- corner_radius: float, corner rounding radius
"""Specialized geometric constructs for mathematical demonstrations.
class TangentLine(Line):
def __init__(self, vmob, alpha, length=1, **kwargs):
"""
Tangent line to a curve.
Parameters:
- vmob: VMobject, curve to find tangent to
- alpha: float, position along curve (0-1)
- length: float, tangent line length
"""
class Elbow(VMobject):
def __init__(self, width=0.2, angle=0, **kwargs):
"""
Right angle indicator.
Parameters:
- width: float, elbow size
- angle: float, elbow orientation
"""
class CubicBezier(VMobject):
def __init__(self, a0, h0, h1, a1, **kwargs):
"""
Cubic Bezier curve.
Parameters:
- a0: np.array, start point
- h0: np.array, first control point
- h1: np.array, second control point
- a1: np.array, end point
"""
class Polygon3D(VMobject):
def __init__(self, *vertices, **kwargs):
"""
3D polygon.
Parameters:
- vertices: 3D points defining polygon vertices
"""
class Sphere(Surface):
def __init__(self, radius=1, **kwargs):
"""
3D sphere.
Parameters:
- radius: float, sphere radius
- resolution: tuple, surface resolution (u, v)
"""from manimgl import *
class ShapeExample(Scene):
def construct(self):
# Create basic shapes
circle = Circle(radius=1, color=BLUE)
square = Square(side_length=2, color=RED)
triangle = Triangle(color=GREEN)
# Position shapes
circle.shift(LEFT * 3)
square.shift(ORIGIN)
triangle.shift(RIGHT * 3)
# Add to scene
self.add(circle, square, triangle)
self.wait()class PolygonExample(Scene):
def construct(self):
# Create custom polygon
vertices = [
np.array([0, 2, 0]),
np.array([-1, 0, 0]),
np.array([1, 0, 0]),
]
custom_shape = Polygon(*vertices, color=YELLOW)
self.add(custom_shape)
self.wait()class GroupExample(Scene):
def construct(self):
# Create and group objects
circle = Circle(color=BLUE)
text = Text("Circle").next_to(circle, DOWN)
group = Group(circle, text)
# Transform the entire group
self.add(group)
self.play(group.animate.scale(2).shift(RIGHT))
self.wait()Install with Tessl CLI
npx tessl i tessl/pypi-manimgldocs