ManimLib2 API Reference

iManim Object

class manimlib2.Manim.iManim(animation_name='ManimOut', backend='pygame')

The central animation object

iManim implements the main animation loop and orchestrates execution of Instructions, frame rendering, and feeding frames to the backend.

It contains the main camera and backend object instances and offers configuration methods to adjust the output frame rate and size.

Parameters
  • animation_name (optional, string) – The name of the animation. Sent to the chosen backend default = “ManimOut”

  • backend (optional, string) – The desired backend. possible values: “pygame”, “MP4” default = “pygame”

property animation_name

The name of the animation

config_backend(pw, ph, frame_rate)

Set up the backend so that it can receive frames

Parameters
  • pw (int) – Dimensions of the frames in pixels

  • ph (int) – Dimensions of the frames in pixels

  • frame_rate (float) – The frame rate in frames per second

config_camera(width, ar, frame_rate, DPI)

Reconfigure the video settings.

Parameters
  • width (float) – The width of the camera frame in Scene Units

  • ar (float) – The aspect ratio of a frame width/height

  • frame_rate (int) – The frame rate in frames per second

  • DPI (int) – Dots per Inch. But really, Pixels per Scene Unit

play_movie(repeat=- 1)

Have the current backend play the movie

property render

True when rendering frames

run(*instructions)

Execute the instructions and render the results

This is where the main animation loop lives

Parameters

*instructions (tuple of Instructions) – The set of instructions that run should run.

static run_parallel(*instructions)

Create an InstructionTree containing parallel instructions

Parameters

*instructions (tuple of Instructions) – The instructions to assemble.

Returns

The assembled instructions

Return type

InstructionTree

static run_sequential(*instructions)

Create an InstructionTree containing sequential instructions

Parameters

*instructions (tuple of Instructions) – The instructions to assemble.

Returns

The assembled instructions

Return type

InstructionTree

property video_directory

The location of the output video file

Mobject

class manimlib2.Mobject.Mobject(data, renderer, clip=None)

Abstract Base Class for all Mobjects.

The Mobject base class defines the interface for Mobjects as used by the ManimLib2 animation engine. It contains the basic coordinate transformation information to transform between internal and external coordinates based on the position, about_point, rotation, and scale attributes.

In Typical usage, a Child class is defined that provides a renderer object containing a render method. At render time, the animation engine will call Mobject.render with a copy of the current canvas. The default render method then calls renderer.render() with the data object and the canvas.

Parameters
  • data (Object) – A representation of the data to be rendered

  • renderer (Object) – An object with a render method that can render the data defined by the data attribute. Must have a render method: renderer.render(data,canvas)

position

The position of the about point in external coordinates

Type

Vector

about_point

The position of the about point in internal coordinates

Type

Vector

rotation

The rotation angle between internal and external coordinates

Type

float

scale

The ratio of distances in the external coordinate system to distances in the internal coordinate system

Type

Vector or float

clip

A PolyBezier path defining a clip region.

Type

PolyBezier

about_center()

Move the about point to the center of the mobject

about_left()

Move the x-coord of the about point to the left bound.

about_lower()

Move the y-coord of the about point to the lower bound.

about_right()

Move the x-coord of the about point to the right bound.

about_upper()

Move the y-coord of the about point to the upper bound.

external2internal(coords)

Convert external coordinates to internal coordinates.

internal2external(coords)

Convert internal coordinates to external coordinates.

render(canvas)

Render the data object onto the requested canvas.

VMobject

class manimlib2.Mobject.VMobject(path=None, pen=None)

A Mobject containing a Bezier path and a Pen to draw it.

VMobject will render an arbitrary open or closed path defined by a PolyBezier curve using a VRender object as the renderer. VRender renders the path according to the attributes of Pen object.

Parameters
  • path (PolyBezier) – A Poly Bezier curve representing a path to be rendered

  • pen (Pen) – A pen representing the appearance of the path.

ImageMobject

class manimlib2.Mobject.ImageMobject(filename, scale_height=None)

A Mobject containing a bitmapped image

Parameters
  • filename (str) – The name of the image file

  • scale_height (optional, float) – The number of Scene Units that the the full height of the image should occupy. The aspect ratio of the image will be maintained. default = 1.0, meaning the image will be 1 Scene Unit tall.

invert()

Invert the image, top to bottom

mirror()

Flip image left to right

render(camera)

Render the data object onto the requested canvas.

set_scale(dpi)

Set the scale prior to rendering

CompositeMobject

class manimlib2.Mobject.CompositeMobject(mobjects=None, names=None)

A Mobject constructed from multiple sub-mobjects.

The CompositeMobject allows sub-mobjects (any of which can also be a CompositeMobject) to be grouped into a single unit. All position, scale, and rotations on the CompositeMobject will effect all Mobjects in the composite such that their individual scales, positions, and rotations relative to one another will remain fixed.

Submobjects can be manipulated through standard array indexing syntax. If a submobject is a CompositeMobject, its members can be access by passing a tuple as the index.

add_mobject(mobject, name=None, preserve_transform=True)

Add a mobject to the collection

Parameters
  • mobject (Mobject) – An instance of a class derived from Mobject

  • name (str) – The name of the mobject for retrieval and manipulation

  • preserve_transform (optional boolean) –

    The coordinates of a mobject (the position, scale, and rotation) are representd by an affine transformation which is applied just prior to rendering. A CompositeMobject has its own transformation which is applied before rendering any submobjects.

    When preserve_transform is True, the added mobject’s coordinates (position, scale, and rotation) are modified by applying the inverse of the CompositeMobject’s transformation effectively undoing it so that its final rendered position on the canvas is the same as it would have been before the call to add_mobject. This modification happens only once at the time that add_mobject is called.

    When false, the added mobject’s coordinates will NOT be modified which, depending on state of the CompositeMobject’s transformation, will could cause its rendered appearance to change.

clear()

Remove all mobjects from the composite

get_mobject(name)

Fetch a mobject from the group. Synonym for __getitem__

Parameters

name (str) – The name of the mobject

group(indices, name)

Place a set of mobjects into composite under a single key

Parameters
  • indices (slice) – An array of the indices (ints or keys) to add to the new composite

  • name (string) – The key under which to store the new composite mobject

pop(name)

Remove a mobject from the composite.

remove_mobject(name)

Remove a mobject from the composite. Synonym for pop.

set_attributes(attribute, value, keys=None)

Set the same attribute on each of the of selected sub-mobjects

Parameters
  • attribute (string) – The name of the attribute

  • value – The desired attribute value

  • keys (optional, iterable of strings) – The keys of the mobjects whose attribute should be set. default = all contained mobjects.

Instruction

class manimlib2.Instruction.Instruction(nextInstructions=[])

A basic node in the Instruction Tree.

Instruction contains an update function holding the code for the instruction as well as links to subsequent instructions.

nextInstructions

The instruction(s) to execute when this instruction finishes

Type

list of Instructions

finished

True when the instruction has finished executing

Type

boolean

addNextInstruction(Instruction)

Add an instruction to be executed when the current one finishes.

If multiple instructions are added they will run in parallel

property nextInstructions

Fetch the list of next instructions.

start(scene)

Execute any additional setup before the first call to update.

update(scene, dt)

Move the instruction forward dt seconds

This is where the code to control the animation goes. To build an Instruction, inherit this class and over-ride the update method.

The animation sequencer will call the update method with a reference to current Scene and a time increment (dt) representing the time to the the next animation frame.

update must return the amount of time actually used by the instruction, has a maximum of dt if the instruction has more work to do or some value less than dt if the instruction finished before dt elapsed.

Parameters
  • scene (Scene instance) – The scene on which to execute the instruction

  • dt (float) – Time to advance the instruction in seconds

Returns

dtUsed – The number of animation seconds that the instruction actually consumed. dtUsed will be less than dt if the instruction finished during dt elapsed

Return type

float

SetAttribute Instruction

class manimlib2.CoreInstructions.SetAttribute(key, attribute, value, mobject=None, duration=0.0, transfer_func=<function linear>)

Set an attribute of a Mobject to the desired value.

If the attribute is callable, it is called with value as the parameter Otherwise, the attribute is set to value

If value is callable, it is called with the current Timing and its return value is used to set the attribute.

eg. obj.attribute = value

obj.attribute = value(time,timing) obj.attribute(value) obj.attribute(value(time,timing))

Parameters
  • key (string) –

  • attribute (string) –

  • value

start(scene)

Animation sequencer calls start before the first call to update.

update(scene, dt)

Update the attribute.

sceneScene

The scene associated with the animation

dtfloat

The amount of time to move forward during this step

AdjustAttribute Instruction

class manimlib2.CoreInstructions.AdjustAttribute(key, attribute, end_value, start_value=None, mobject=None, duration=0.0, transfer_func=<function smooth>)

Incrementally update a numeric attribute over a fixed period of time.

The attribute is updated as:

obj.attribute = (new_value-old_value)*transfer_function(alpha)

where alpha is the ratio of the current time used by the instruction to the requested duration

Parameters
  • key (str) – The ID of the object to update

  • attribute (string) – The name of the attribute

  • end_value (type undefined) – The final value of the attribute.

  • start_value (optional, type undefined) – The starting value of the attribute. If start_value = None, the current value of the attribute is used. default = None

  • mobject (optional object) – Provide a direct reference to the object rather than a key. If mobject is None, the key is used to look the object up. If mobject is not None, the key is ignored. default = None

  • duration (optional, float) – The amount of time in seconds over which to update the attribute. default: 0.0

  • transfer_func (callable) –

    A function that maps alpha to a new ratio between 0 and 1

    ratio = transfer_func(alpha)

    default = smooth

  • nextInstructions (List of instructions) – The subsequent branches in the instruction tree.

start(scene)

Animation sequencer calls start before the first call to update.

manimlib2.Backend module

Created on Tue Sep 17 12:53:16 2019

@author: Fred

class manimlib2.Backend.MP4Backend(pixel_width, pixel_height, frame_rate, outName, outDir='.\\', showVideo=False)

Bases: object

Use ffmpeg to write mp4s adapted from manimlib.scene.scenefilewriter

addFrame(frame)

buffer the frame

close_movie_pipe(pipe)
end()

Open a pipe to ffmpeg

play_movie(*args)
start()
class manimlib2.Backend.PyGameBackend(pixel_width, pixel_height, frame_rate)

Bases: object

Renders a pygame scene.

size

The size of the screen in pixels

Type

2 element array of floats

scale

The number of pixels per model spatial unit

Type

2 element array of floats

offset

The number of pixels to offset the zero point

Type

2 element array of floats

addFrame(frame)
end()
property frame_rate
play_movie(repeat=- 1)
start()

Nothing to do here…

manimlib2.BasicInstructions module

A set of basic instructions.

Created on Sat Dec 7 22:53:04 2019 @author: Fred

class manimlib2.BasicInstructions.AboutCenter(key)

Bases: manimlib2.CoreInstructions.SetAttribute

Set the about point to the center of the bounding box

Parameters

key (dict key) – Name of the mobject to scale

class manimlib2.BasicInstructions.AboutLeft(key)

Bases: manimlib2.CoreInstructions.SetAttribute

Move x coord of the about point to the left side of the bounding box

Parameters

key (dict key) – Name of the mobject to scale

class manimlib2.BasicInstructions.AboutLower(key)

Bases: manimlib2.CoreInstructions.SetAttribute

Move y coord of the about point to the bottom of the bounding box

Parameters

key (dict key) – Name of the mobject to scale

class manimlib2.BasicInstructions.AboutRight(key)

Bases: manimlib2.CoreInstructions.SetAttribute

Move x coord of the about point to the right side of the bounding box

Parameters

key (dict key) – Name of the mobject to scale

class manimlib2.BasicInstructions.AboutUpper(key)

Bases: manimlib2.CoreInstructions.SetAttribute

Move y coord of the about point to the top of the bounding box

Parameters

key (dict key) – Name of the mobject to scale

class manimlib2.BasicInstructions.AddMobject(key, mobject)

Bases: manimlib2.Instruction.Instruction

Add a Mobject to the scene.

Parameters
  • key (dictionary key) – Key used to reference the Mobject

  • mobject (Mobject) – An instance of a class derived from Mobject

update(scene, dt)

Add the mobject.

class manimlib2.BasicInstructions.AddMobjects(keys, mobjects)

Bases: manimlib2.Instruction.Instruction

Add a Mobject to the scene.

Parameters
  • keys (list of keys) – Keys used to reference the Mobjects

  • mobjects (list of Mobjects) – A list of objects derived from Mobject

update(scene, dt)

Add the mobject.

class manimlib2.BasicInstructions.AdjustAboutPoint(key, value)

Bases: manimlib2.CoreInstructions.SetAttribute

Adjust the about point relative to its current location

Parameters
  • key (dict key) – Name of the mobject to scale

  • offset (Vector) – The offset to apply to the current about_point

start(scene)

Calculate the new value of the about_point

class manimlib2.BasicInstructions.AlignWithPath(key, path, end_points, duration=0.1, transfer_func=<function linear>)

Bases: manimlib2.CoreInstructions.SetAttribute

Align a mobject’s rotation angle with slope of path.

Parameters
  • key (dict key) – The mobject to adjust

  • path (PolyBezier) – A PolyBezier curve defining the path

  • start_point (optional, float 0.0<=start_point<=1.0) – The starting point along the path default = 0.0

  • end_point (optional, float) – The ending point along the path default = start_point

  • duration (optional float) – The number of seconds the trip should take default = 0.0

value_func(time, timing)
class manimlib2.BasicInstructions.BringToTop(key)

Bases: manimlib2.Instruction.Instruction

Bring a mobject to the top of the z-order

Parameters

key (dictionary key) – Key used to reference the Mobject

update(scene, dt)

Move the instruction forward dt seconds

This is where the code to control the animation goes. To build an Instruction, inherit this class and over-ride the update method.

The animation sequencer will call the update method with a reference to current Scene and a time increment (dt) representing the time to the the next animation frame.

update must return the amount of time actually used by the instruction, has a maximum of dt if the instruction has more work to do or some value less than dt if the instruction finished before dt elapsed.

Parameters
  • scene (Scene instance) – The scene on which to execute the instruction

  • dt (float) – Time to advance the instruction in seconds

Returns

dtUsed – The number of animation seconds that the instruction actually consumed. dtUsed will be less than dt if the instruction finished during dt elapsed

Return type

float

class manimlib2.BasicInstructions.Draw(key, duration=0.0)

Bases: manimlib2.Instruction.Instruction

Animate the drawing of a VMobject

Parameters
  • key (string) – The key to the Vmobject in the scene

  • duration (float) – The time to finish drawing

start(scene)

Save the original data object from the mobject

update(scene, dt)

Replace the data object with a partially drawn data object

class manimlib2.BasicInstructions.DrawText(key, duration)

Bases: manimlib2.Instruction.InstructionTree

start(scene)

Ok, Let’s unpack!

class manimlib2.BasicInstructions.Emphasize(key, scale_mult=2.0, duration=0.0)

Bases: manimlib2.CoreInstructions.AdjustAttribute

Change the scale of a mobject and then return it to its original size

Parameters
  • key (dict key) –

  • scale_mult (optional float) – The multiplier to apply to the original scale. default = 2.0

  • duration (float) – Number of seconds that the animation should last.

start(scene)

Animation sequencer calls start before the first call to update.

class manimlib2.BasicInstructions.FollowPath(key, path, duration, end_points=None, transfer_func=<function linear>)

Bases: manimlib2.CoreInstructions.SetAttribute

Have a mobject follow a pre-defined path

Parameters
  • key (dict key) – The mobject to move along the path

  • path (PolyBezier) – A PolyBezier curve defining the path

  • end_points (iterable) – The starting and ending point on the Bezier curve

  • duration (float) – The number of seconds the trip should take

value_func(time, timing)
class manimlib2.BasicInstructions.GrowArrow(key, duration, transfer_func=<function smooth>)

Bases: manimlib2.CoreInstructions.AdjustAttribute

Grow an arrow from zero to full size

start(scene)

Animation sequencer calls start before the first call to update.

class manimlib2.BasicInstructions.Move(key, displacement, duration=0.0, transfer_func=<function smooth>)

Bases: manimlib2.CoreInstructions.AdjustAttribute

Move the object the desired amount relative its current position

Parameters
  • key (dict key) – The name of the mobject to move

  • displacement (Vector) – The new coordinates of the mobject in Scene Units

  • duration (optional float) – The amount of time over which to move the mobject. default = 0.0, instantaneous

  • transfer_func (optional callable) – The transfer function mapping alpha to the fraction of the total distance moved ratio = transfer_func(alpha) default = smooth

start(scene)

Animation sequencer calls start before the first call to update.

class manimlib2.BasicInstructions.MoveCamera(position, duration=0.0)

Bases: manimlib2.CoreInstructions.AdjustAttribute

Move the camera within the scene

Parameters
  • position (array_like, float) – The position of the center of the camera frame in Scene Units

  • duration (float) – The amount of time over which to move the camera. default = 0.0, instantaneous

class manimlib2.BasicInstructions.MoveTo(key, position, duration=0.0, transfer_func=<function smooth>)

Bases: manimlib2.CoreInstructions.AdjustAttribute

Absolute Move of a mobject to a new spot in the Scene.

Parameters
  • key (dict key) – The name o

  • position (Vector) – The new coordinates of the mobject in Scene Units

  • duration (optional float) – The amount of time over which to move the mobject. default = 0.0, instantaneous

  • transfer_func (optional callable) – The transfer function mapping alpha to the fraction of the total distance moved default = smooth

start(scene)

Animation sequencer calls start before the first call to update.

class manimlib2.BasicInstructions.RemoveMobject(key)

Bases: manimlib2.Instruction.Instruction

Remove a Mobject from the scene.

Parameters

key (dict key) – The name of the mobject to remove

update(scene, dt)

Remove the mobject.

class manimlib2.BasicInstructions.Repeat(instruction, num)

Bases: manimlib2.Instruction.Instruction

Repeat an instruction a fixed number of times

start(scene)

Execute any additional setup before the first call to update.

update(scene, dt)

Move the instruction forward dt seconds

This is where the code to control the animation goes. To build an Instruction, inherit this class and over-ride the update method.

The animation sequencer will call the update method with a reference to current Scene and a time increment (dt) representing the time to the the next animation frame.

update must return the amount of time actually used by the instruction, has a maximum of dt if the instruction has more work to do or some value less than dt if the instruction finished before dt elapsed.

Parameters
  • scene (Scene instance) – The scene on which to execute the instruction

  • dt (float) – Time to advance the instruction in seconds

Returns

dtUsed – The number of animation seconds that the instruction actually consumed. dtUsed will be less than dt if the instruction finished during dt elapsed

Return type

float

class manimlib2.BasicInstructions.Rotate(key, angle, duration=0.0, transfer_func=<function smooth>)

Bases: manimlib2.CoreInstructions.AdjustAttribute

Absolute rotation of a mobject wrt its default orientation.

Parameters
  • key (dict key) – The name of the mobject to be moved

  • angle (float) – The new rotation angle in radians

  • duration (optional float) – The amount of time over which to rotate the mobject. default = 0.0, instantaneous

class manimlib2.BasicInstructions.Scale(key, xscale, yscale=None, duration=0.0, transfer_func=<function linear>)

Bases: manimlib2.CoreInstructions.AdjustAttribute

Scale a mobject.

Parameters
  • key (dict key) – Name of the mobject to scale

  • xscale (float) – x-axis scale factor

  • yscale (optional float) – y-axis scale factor if yscale is none, scale the same as x default = None

  • duration (optional float) – Duration over which to scale the mobject

class manimlib2.BasicInstructions.SetAboutPoint(key, about_point)

Bases: manimlib2.CoreInstructions.SetAttribute

Set the about point of a mobject

Parameters
  • key (dict key) – Name of the mobject to scale

  • about_point (Vector) – The new coordinates of the about_point

class manimlib2.BasicInstructions.Wait(time, nextInstructions=[])

Bases: manimlib2.Instruction.Instruction

Pause execution of the animation branch.

Parameters

time (float) – Time in seconds to pause the animation branch

update(scene, dt)

Don’t do anything. Just sit here.

class manimlib2.BasicInstructions.ZoomCamera(yzoom, duration=0.0, xzoom=None)

Bases: manimlib2.CoreInstructions.AdjustAttribute

Zoom camera in or out about the center of the frame

The Zoom level is absolute and tied to Scene Units Zoom = 1 means that there is 1 Scene Unit per camera frame Zoom = 0.5 means that there are 0.5 Scene Units per camera frame

Parameters
  • yzoom (float) – The zoom value for the y-axis

  • duration (float) – The amount of time over which to execute the zoom. default = 0.0, instantaneous

  • xzoom (optional float) – The zoom value fo the x-axis. If xzoom is None, it is scaled to preserve the aspect ratio default = None

start(scene)

Over ride start to fix the aspect ratio.

manimlib2.Bezier module

Bezier Handling Routines

A collection of classes to handle creation and manipuplation of Cubic Bezier curves.

Many algorithms adapted from “A Primer on Bezier Curves” https://pomax.github.io/bezierinfo/

Code for SVG Paths adapted from Grant Sanderson’s Manimlib

Created on Fri Oct 25 08:01:58 2019 @author: G.Ruch

class manimlib2.Bezier.BezierCurve(coefficients)

Container for a Cubic Bezier Curve

Holds the coeffcients of a Cubic Bezier curve defined by:

B(t) = p0*(1-t)**3 + p1*((1-t)**2)*t * p2*(1-t)*(t**2) + p3*(t**3)

p0, p1, p2, p3

The cubic Bezier coefficients.

Type

Vector

B(t, deriv=0.0)

Calculate the value of the Bezier segment at t

Calculates B(t) defined as with 0<=t<=1 B(t) = p0*(1-t)**3 + p1*3*((1-t)**2)*t * p2*3*(1-t)*(t**2) + p3*(t**3)

Parameters
  • t (float) – The Bezier parameter limited to 0<=t<=1

  • deriv (default int) – The desired derivative. default = 0.0 (no derivative)

Returns

D – The coordinates of a point along the curve at t

Return type

array of floats

D(d)

Find the point a proportional distance d along the curve.

The distance along the curve is not linear in t. The input parameter d is approximately linear with distance along the curve.

Parameters

d (float, 0.0<=d<=1.0) – The proportional distance along the curve.

Returns

D – The coordinates of the point a proportinal distance d along the curve

Return type

array of floats

bounding_box()

Calculate the box (or cube in R3) that encloses the curve

Calculated by setting dB/dt = 0 and finding the roots of the resulting polynomial in each axis.

Returns

upper_right, lower_left – Vectors indicating the upper right and lower left corners of the bounding box

Return type

ndarray of Vectors

property distances

Approximate distance along the curve at a discrete set of t values

split(t)

Split the Bezier curve at t into two pieces.

Uses de Casteljau’s algorithm to divide the curve into a left and a right sub curve

Parameters

t (float) – The split point as a fraction of the total curve. 0<=t<=1

property t_lookup

Build a time versus proportional distance lookup table.

class manimlib2.Bezier.PolyBezier(segments=None)

Container for a connected Cubic Poly-Bezier curve

Contains a set of connected Bezier Curves, where the end point of the curve at n-1 is the same as the starting point of the curve at n.

num_segments

The number of Bezier segments

Type

int

B(t)

Calcuate the coordinates of the curve with 1<=t<=0

Bdprime(t)

Calcuate the coordinates of the curve with 1<=t<=0

Bprime(t)

Calcuate the coordinates of the curve with 1<=t<=0

T(x, niter=20)

Get the value of t at the first coordinate.

Assumes that the curve is singular in the first coordinate.

addSegment(segment)

Add a Bezeir Segement to the curve

Parameters

segment (BezierSegment) – The Bezier Segment to add to the curve

add_point(t)

Add an end point at t. Creates another segment.

property bounding_box

Calculate and return coordinates of the bounding box

Returns

bounding_box – Coordinates of the lower left and upper right corners of a box whose sides either coincide with the curve’s endpoints or are tangent to the curve’s extremities on each axis.

Return type

2x3 ndarray of floats

calc_bounding_box()

Calculate the coordinates of the Bezier Curve bounding box

Returns

bounding_box – Coordinates of the lower left and upper right corners of a box whose sides either coincide with the curve’s endpoints or are tangent to the curve’s extremities on each axis.

Return type

2x3 ndarray of floats

connectLinear(data, close=False)

Connect a set of points in 3-space with straight lines

Adds the curve to the current set of points

Parameters
  • data (nx3 iterable of floats) – The n data points to connect

  • close (optional Boolean) – Connect last point back to the first when True default = False

connectSmooth(data)

Smoothly connect a set of points in 3-space with Cubic Bezier segs

Adds the curve to the current set of points

Apologies for the barely readable numpy code below. At some point it should be reworked into an intelligible form.

Parameters

data (nx3 iterable of floats) – A set of n triplets representing 3-space coordinates to be connected.

find_segment(t)

Find the index and t for a segment given t for the polycurve

Parameters

t (float) – T

property lengths

The length of each segment

property points

Return the Bezier coefficients as an n*4x3 ndarray

shift(displacement)

Shift the curve’s position by the desired displacement.

Adds the displacement vector to all of the points defining the curve

Parameters

displacement (Vector) – The displacement vector to add to the points

split(t)

Split the Bezier curve at t into two pieces.

Let 0<=t<=1 so that it represents a portion of the entire shape. split finds locates the correct BezierSegment and divides it using BezierSegment.split

Parameters

t (float) – The split point as a fraction of the total curve. 0<=t<=1

class manimlib2.Bezier.SVGPolyBezier(path_string)

Generate a PolyBezier curve from an SVG path string

Adapted from Manimlib by Grant Sanderson

generate_points()

Parse the SVG Path string and generate Bezier control points

manimlib2.Camera module

Created on Tue Sep 17 16:03:48 2019

@author: Fred

class manimlib2.Camera.Camera(pixel_width, pixel_height, frame_height, frame_rate, frame_width=0.0, camera_x_center=0.0, camera_y_center=0.0, camera_rotation=0.0, **kwargs)

Holds a single camera frame.

Contains information to convert from scene coords to pixel coords. Contains the current camera frame. Offers a cairo context onto which Mobjects can render themselves

frame

The current camera frame represented as an array of RGBA pixels

Type

hxwx4 ndarray of floats

pixelsPerFrame

The number of pixels per camera frame

Type

1x2 ndarray, int

sceneUnitsPerFrame

The number of Scene units in a single camera frame

Type

1x2 ndarray, float

cameraPosition

The position of the center of the camera window in Scene Coordinates

Type

1x2 ndarray, float

ctx

A Cairo context attached to the frame for rendering

Type

cairo.Context

clearFrame()

Clear the frame to prepare for next image.

showFrame()

Use PIL to display the current camera frame

manimlib2.CommonMobs module

A small collection of basic mobjects

Created on Wed Nov 20 15:23:10 2019 @author: gtruch

class manimlib2.CommonMobs.Arc(radius, start_angle, stop_angle, e=0.0, pen=None)

Bases: manimlib2.CommonMobs.Circle

A circular arc

Parameters
  • radius (float) – Radius of curvature

  • start_angle (float) – The angle in radians wrt the x-axis where the arc starts

  • stop_angle (float) – The angle in radians wrt the x-axis where the arc stops

property start_angle
property stop_angle
class manimlib2.CommonMobs.Arrow(tail_pos, head_pos, head_size=1.0, pen=None, head_pen=None)

Bases: manimlib2.Mobject.CompositeMobject

A basic arrow consisting of a line with a pointy tip.

Provides several positioning helpers.

start, end

The start and end points of the arrow. Start is the tail, end is the head.

Type

Vector

pen, head_penoptional Pen

The pen used to draw the arrow

about_head()

Position changes and rotations are about the head of the arrow.

about_tail()

Position changes and rotations are about the tail of the arrow.

property arrow_width
property color
property head_pos

Position of the head of the arrow in Scene Cooordinates.

property magnitude
property opacity
property tail_pos

Position of the tail of the arrow in Scene Cooordinates.

class manimlib2.CommonMobs.ArrowHead(length=0.2, width=0.15, back=0.05, size=1.0, pen=None)

Bases: manimlib2.Mobject.VMobject

set_head_size(size)
class manimlib2.CommonMobs.Circle(radius, e=0.0, pen=None, coordinates=None)

Bases: manimlib2.Mobject.VMobject

A Circle

Parameters
  • radius (float) – The radius of hte circle

  • coordinates (Coordinates, optional) – An instance of a Coordinates object containing the initial position and orientation the circle.

  • pen (Pen) – An instance of a Pen object with rendering instructions

property radius
class manimlib2.CommonMobs.CrossHair(size=0.25, pen=None, coordinates=None)

Bases: manimlib2.Mobject.VMobject

A crosshair

class manimlib2.CommonMobs.Dimension(left_point, right_point)

Bases: manimlib2.Mobject.CompositeMobject

A dimension bracket with a label

left

The coordinates of the left pointer

Type

Vector

right

The coordinates of the right pointer

Type

Vector

property left_point
property length
property right_point
class manimlib2.CommonMobs.DoubleArrow(tail_pos, head_pos, head_size=1.0, pen=None, head_pen=None)

Bases: manimlib2.CommonMobs.Arrow

class manimlib2.CommonMobs.EngineerPaper(size=Vector([8.5, 11., 0.]), gridDensity=7.0, topMarg=0.04, botMarg=0.0, leftMarg=0.09, rightMarg=0.04)

Bases: manimlib2.Mobject.CompositeMobject

A piece of green engineering paper to draw on

class manimlib2.CommonMobs.Grid(size, spacing, pen=None)

Bases: manimlib2.Mobject.VMobject

A grid of lines.

size

The size of the grid: [sx, sy]

Type

array of float

spacing

The x and y grid spacing

Type

array of float

class manimlib2.CommonMobs.Line(point1, point2, pen=None)

Bases: manimlib2.Mobject.VMobject

A straight line.

Parameters
  • 1 (point) – The coordinates of the first end point

  • 2 (point) – The coordinates of the second end point

property point1
property point2
class manimlib2.CommonMobs.R_Triangle(vertex, pen=None)

Bases: manimlib2.Mobject.VMobject

property vertex
class manimlib2.CommonMobs.Rectangle(size, pen=None, coordinates=None)

Bases: manimlib2.Mobject.VMobject

A rectangle.

property size
class manimlib2.CommonMobs.SVGMobject(filename)

Bases: manimlib2.Mobject.VMobject

manimlib2.Config module

Customizable configuration objects

class manimlib2.Config.AbaondonedConfig(iniSettings)

Bases: manimlib2.Config.Config

class manimlib2.Config.CameraConfig(iniSettings={})

Bases: manimlib2.Config.Config

Configuration settings for the camera module

pixel_height, pixel_width

Dimensions of the camera window in pixels

Type

int

frame_height, frame_width

Dimensions of the Scene contained within the camera window in Scene Units

Type

float

camera_x_center, camera_y_center

Position of the center of the camera window in Scene Coordinates

Type

float

camera_rotation

The camera rotation angle in radians

Type

float

frame_rate

Animation speed in frames per second

Type

int

setHighQuality()
setLowQuality()
setMediumQuality()
class manimlib2.Config.Config(defaults, iniSettings)

Bases: dict

Config base class

Allows access of configuration parameters using either dictionary keys or as attributes of the config object using dot notation.

reconfigure(settings, convert_types=True)

Ingest additional configuration settings

If settings in the dictionary are from an ini file, the dictionary values may be strings. In that case, they are type converted based on the type information in the defaults dict

Parameters
  • settings (dict) – Incoming configuration Settings in simple key: value pairs. Type converted according to type information in default dict.

  • convert_types (optional bool) – If True, types are converted. If False, types are left as they are default = True

class manimlib2.Config.DirectoryConfig(iniSettings)

Bases: manimlib2.Config.Config

Output Directory configuration settings

media_dir

Base directory for all media files default = None

Type

String

video_dir

Subdirectory for output video files default = None

Type

String

video_output_dir

Additional name for video_dir? default = None

Type

String

tex_dir

Subdirectory for output tex files default = None

Type

String

class manimlib2.Config.FileWriterConfig(iniSettings)

Bases: manimlib2.Config.Config

Configuration settins for File Writer

save_last_frame

default = False

Type

Boolean

save_pngs

default = False

Type

Boolean

save_as_gif

default = False

Type

Boolean

png_mode

default = ‘RGB’

Type

String

movie_file_extension

default = ‘.mp4’

Type

String

file_name

default = None

Type

String

input_file_path

default = ‘.'

Type

Striug

class manimlib2.Config.SceneConfig(iniSettings)

Bases: manimlib2.Config.Config

Configuration settings for Scene

skip_animations

default = False

Type

Boolean

start_at_animation_number

default = None

Type

Int

end_at_animation_number

default = None

Type

Int

leave_progress_bars

default = False

Type

Boolean

manimlib2.Coordinates module

Affine transformations

Created on Wed Dec 11 15:19:42 2019

@author: G.Ruch

class manimlib2.Coordinates.Affine2d(offset=None, scale=None, rotation=0.0)

Matrix representing a 2d affine transformation.

class manimlib2.Coordinates.Coordinates(position=None, about_point=None, rotation_angle=None, scale=None)

Handle Affine transformations between coordinate spaces.

The transformation represents a Rotation, Scale and Translation around an about point.

position

Position of the about point in the external coordinate space A

Type

Vector

about_point

Position of the about point in the internal coordinate space

Type

Vector

scale

The ratio of distances in the external space to distances in the internal space

Type

Vector

rotation_angle

The rotation angle of space Y with respect to space X

Type

float

transform_matrix

The affine transformation matrix based on Xposition, Yposition, scale, and rotation_angle

Type

read only 3x3 ndarray of floats

property about_point

Position of the About Point in internal coordinates.

external2internal(mcoords)

Convert external coordinates to internal coordinates.

internal2external(scoords)

Convert internal coordinates to external coordinates.

property position

Position of the About Point in external coordinates.

property rotation_angle

Rotation angle.

property scale

Get the scale.

property transform_matrix

Return the current transform matrix.

class manimlib2.Coordinates.Vector(x, y=0.0, z=0.0)

Three dimensional vector to represent a point in 3-space

x,y,z

cartesian components

Type

float

r,theta,phi

Spherical components

Type

float

classmethod asSpherical(r, theta, phi=1.5707963267948966)

Initialize with spherical coordinates

Parameters
  • r (float) – The magnitude and azimuthal angle (in radians) respectively

  • theta (float) – The magnitude and azimuthal angle (in radians) respectively

  • phi (optional, float) – The polar angle in radians (default = pi/2)

class manimlib2.Coordinates.Vectors(data)

Flexible ndarray to represent a set of 3D vectors.

apply_affine_transform(transform_matrix)

Apply an affine transformation

Parameters

transform_matrix (3x3 or 4x4 ndarray of floats) –

The transform matrix. If 3x3:

A 2d transformation is applied and z-coordinates are maintained

If 4x4:

A 3d transformation is applied

get_vector(index)

Get a vector

manimlib2.CoreInstructions module

The core instruction set.

These are the most abstract instructions. Other more concrete instructions are built from these basic forms.

Created on Sat Dec 7 22:00:16 2019 @author: Fred

class manimlib2.CoreInstructions.AdjustAttribute(key, attribute, end_value, start_value=None, mobject=None, duration=0.0, transfer_func=<function smooth>)

Bases: manimlib2.CoreInstructions.SetAttribute

Incrementally update a numeric attribute over a fixed period of time.

The attribute is updated as:

obj.attribute = (new_value-old_value)*transfer_function(alpha)

where alpha is the ratio of the current time used by the instruction to the requested duration

Parameters
  • key (str) – The ID of the object to update

  • attribute (string) – The name of the attribute

  • end_value (type undefined) – The final value of the attribute.

  • start_value (optional, type undefined) – The starting value of the attribute. If start_value = None, the current value of the attribute is used. default = None

  • mobject (optional object) – Provide a direct reference to the object rather than a key. If mobject is None, the key is used to look the object up. If mobject is not None, the key is ignored. default = None

  • duration (optional, float) – The amount of time in seconds over which to update the attribute. default: 0.0

  • transfer_func (callable) –

    A function that maps alpha to a new ratio between 0 and 1

    ratio = transfer_func(alpha)

    default = smooth

  • nextInstructions (List of instructions) – The subsequent branches in the instruction tree.

start(scene)

Animation sequencer calls start before the first call to update.

manimlib2.CoreInstructions.GetAttribute(key, attribute, argument=None)

Get the value of an attribute.

Parameters
  • key (string) – The key to fetch the object

  • attribute (string) – The name of the attribute

  • argument (undefined type) – If the attribute is callable, pass this argument

class manimlib2.CoreInstructions.Group(name, mobjects, nextInstructions=[])

Bases: manimlib2.Instruction.Instruction

Group a set of mobjects to lock them spatially together.

update(scene, dt)

Move the instruction forward dt seconds

This is where the code to control the animation goes. To build an Instruction, inherit this class and over-ride the update method.

The animation sequencer will call the update method with a reference to current Scene and a time increment (dt) representing the time to the the next animation frame.

update must return the amount of time actually used by the instruction, has a maximum of dt if the instruction has more work to do or some value less than dt if the instruction finished before dt elapsed.

Parameters
  • scene (Scene instance) – The scene on which to execute the instruction

  • dt (float) – Time to advance the instruction in seconds

Returns

dtUsed – The number of animation seconds that the instruction actually consumed. dtUsed will be less than dt if the instruction finished during dt elapsed

Return type

float

class manimlib2.CoreInstructions.SetAttribute(key, attribute, value, mobject=None, duration=0.0, transfer_func=<function linear>)

Bases: manimlib2.Instruction.Instruction

Set an attribute of a Mobject to the desired value.

If the attribute is callable, it is called with value as the parameter Otherwise, the attribute is set to value

If value is callable, it is called with the current Timing and its return value is used to set the attribute.

eg. obj.attribute = value

obj.attribute = value(time,timing) obj.attribute(value) obj.attribute(value(time,timing))

Parameters
  • key (string) –

  • attribute (string) –

  • value

start(scene)

Animation sequencer calls start before the first call to update.

update(scene, dt)

Update the attribute.

sceneScene

The scene associated with the animation

dtfloat

The amount of time to move forward during this step

class manimlib2.CoreInstructions.Timing(duration, transfer_func=<function linear>)

Bases: object

Handle timing for instructions

duration

The total amount of time requested

Type

float

time_left

The amount of time yet to be used (duration - time_used)

Type

float

time_used

The total amount of time used during the current frame

Type

float

total_time_used

The total time used for all frames

Type

float

alpha

the ratio of total_time_used/duration alpha is modified by the chosen transfer function.

Type

float

property alpha
property time_left
property time_used

Time used during last call to update.

property total_time_used

Total time used during all calls to update.

update(dt)
class manimlib2.CoreInstructions.Transform(key, target, duration=0.0)

Bases: manimlib2.Instruction.Instruction

Smoothly Transform one VMobject into another

Parameters
  • key (dict key) – The key for the vmobject to transform

  • target (VMobject) – The mobject that we wish to become

  • duration (float) – The time in seconds for the transformation to occur

start(scene)

Let’s get ready to rumble

update(scene, dt)

Move the instruction forward dt seconds

This is where the code to control the animation goes. To build an Instruction, inherit this class and over-ride the update method.

The animation sequencer will call the update method with a reference to current Scene and a time increment (dt) representing the time to the the next animation frame.

update must return the amount of time actually used by the instruction, has a maximum of dt if the instruction has more work to do or some value less than dt if the instruction finished before dt elapsed.

Parameters
  • scene (Scene instance) – The scene on which to execute the instruction

  • dt (float) – Time to advance the instruction in seconds

Returns

dtUsed – The number of animation seconds that the instruction actually consumed. dtUsed will be less than dt if the instruction finished during dt elapsed

Return type

float

manimlib2.CoreInstructions.linear(t)
manimlib2.CoreInstructions.sigmoid(x)
manimlib2.CoreInstructions.smooth(t, inflection=6.0)
manimlib2.CoreInstructions.there_and_back(t)

manimlib2.CustomMobs module

Created on Sat Sep 12 09:15:07 2020

@author: Fred

manimlib2.Instruction module

The base level Instruction and InstructionTree classes.

Instruction is a node in a tree. Each contains a list of links to subsequent instruction(s). The code refereced by Instruction executes and, when it’s finished, the instructions referenced by the forward links are executed in parallel, thus opening further branches on the tree. If an Instruction contains no forward links, the branch will terminate.

The InstructionTree is a special Instruction that serves to contain an internal set of Instructions. Any forward linked Instruction(s) will not exectue until all of the internal Instructions complete, effectivley merging excution branches of the tree back into a single node. Any of the internal Instruction in an InstructionTree may itself be an InstructionTree allowing one to nest complex sets of instructions inside of the tree

The animation sequencer begins at the head of the tree, which is an InstructionTree instance, and executes the instructions in the order described by the tree structure.

Created on Fri Sep 6 15:05:28 2019 @author: G. Ruch

class manimlib2.Instruction.Instruction(nextInstructions=[])

Bases: object

A basic node in the Instruction Tree.

Instruction contains an update function holding the code for the instruction as well as links to subsequent instructions.

nextInstructions

The instruction(s) to execute when this instruction finishes

Type

list of Instructions

finished

True when the instruction has finished executing

Type

boolean

addNextInstruction(Instruction)

Add an instruction to be executed when the current one finishes.

If multiple instructions are added they will run in parallel

calcTimeUsed(timeLeft, dt)
property finished
property nextInstructions

Fetch the list of next instructions.

start(scene)

Execute any additional setup before the first call to update.

update(scene, dt)

Move the instruction forward dt seconds

This is where the code to control the animation goes. To build an Instruction, inherit this class and over-ride the update method.

The animation sequencer will call the update method with a reference to current Scene and a time increment (dt) representing the time to the the next animation frame.

update must return the amount of time actually used by the instruction, has a maximum of dt if the instruction has more work to do or some value less than dt if the instruction finished before dt elapsed.

Parameters
  • scene (Scene instance) – The scene on which to execute the instruction

  • dt (float) – Time to advance the instruction in seconds

Returns

dtUsed – The number of animation seconds that the instruction actually consumed. dtUsed will be less than dt if the instruction finished during dt elapsed

Return type

float

class manimlib2.Instruction.InstructionTree(initialSequence=[], nextInstructions=[])

Bases: manimlib2.Instruction.Instruction

Wait for a set of instructions to terminate before termination

instructions

The instructions to execute

Type

List of Instructions

add_parallel(instructions)
add_sequential(instructions)

Add a set of sequenctial instructions

Parameters

instructions (list of Instruction instances) – The list of instructions to add to the tree

start(scene)

Send start signal to the leading instructions

update(scene, dt)

Allow all instructions in the merge to execute

manimlib2.PlotMobject module

Created on Mon Nov 25 12:32:16 2019

@author: GtRuch

class manimlib2.PlotMobject.PlotMobject(xRange=Vector([0., 0.1, 0. ]), yRange=Vector([0., 0.1, 0. ]), xScale=1.0, yScale=1.0, axis_pen=<manimlib2.Render.Pen object>, plot_pen=<manimlib2.Render.Pen object>)

Bases: manimlib2.Mobject.CompositeMobject

A thing to make plots with

xRange, yRange
Type

nx2 array of floats

xScale, yScale
Type

float

add_data(new_data)

Add data to the plot

Parameters

new_data (nx3 array of floats) – A list of n data points to add to the plot

plot_func(func, parm)

Plot the function.

Parameters
  • func (callable) – A callable that takes a parameter stored as elements of param and returns a numerical value

  • param (iterable of parameters) – The parameters taken by func

manimlib2.PlotMobs module

Created on Fri Apr 24 11:00:57 2020

@author: Fred

class manimlib2.PlotMobs.CoordAxis(screen_size, grid_size, major_spacing=1.0, minor_spacing=0.2, label_offset=- 0.2, label_orientation=0.0, origin=0)

Bases: manimlib2.Mobject.CompositeMobject

A one dimensional coordinate axis with axis labels and tick marks.

property label_offset
property label_orientation
property length
set_horizontal_orientation()
set_vertical_orientation()
property title
property title_offset
property title_orientation
class manimlib2.PlotMobs.CoordGrid(screen_size, grid_size, major_spacing, minor_spacing=None, origin=None, major_pen=None, minor_pen=None)

Bases: manimlib2.Mobject.CompositeMobject

property opacity
class manimlib2.PlotMobs.PlotMark(dot_radius=1.0, dot_pen=None, xlength=0.0, xpen=None, ylength=0.0, ypen=None, xlabel=None, xl_offset=0.0, ylabel=None, yl_offset=0.0, position=None)

Bases: manimlib2.Mobject.CompositeMobject

A dot with marker lines for marking plots-

dot_radius
Type

float

dot_pen, xpen, ypen
Type

Pen

xlength, ylength
Type

float

property dot_fill_opacity
property dot_opacity
property dot_stroke_opacity
property marker_pos
property opacity
property xlabel
property xlabel_opacity
property xline_opacity
property ylabel
property ylabel_opacity
property yline_opacity
class manimlib2.PlotMobs.PlotPoints(points, radius=0.1)

Bases: manimlib2.Mobject.CompositeMobject

Stores a set of individual PlotMarks to manipulate on a graph

about_stored_point(index)

Move the about point to one of the stored points

Parameters

index (int) – The index of the desired point

add_point(point)

Append a point to the collection

get_point(index)
property points

manimlib2.Render module

Rendering classes

Created on Fri Dec 20 12:34:18 2019

@author: GtRuch

class manimlib2.Render.CairoRender

Bases: manimlib2.Render.Render

Abstract base class for Cairo Render.

parent_render(mobject, camera)

Universal Cairo rendering

Handle matrix manipulations Set the clip region call the child render

render(data, camera)

Render the data on the cairo context contained in camera

set_path(path, context)

Draw the path described by the bezier curve into the context

Parameters
  • path (PolyBezier) – The path to set.

  • context (Cairo Context) – The context on which to set the path

class manimlib2.Render.CompositeRender

Bases: manimlib2.Render.CairoRender

Render a group of mobjects

Position and rotation information are set in the tranform matrix before each call to the render for the individual mobjects.

render(mobject, camera)

Render the data on the cairo context contained in camera

class manimlib2.Render.ImageRender

Bases: manimlib2.Render.CairoRender

render(mobject, camera)

Render the image into the camera frame

class manimlib2.Render.Pen(stroke_color='#FFFFFF', stroke_opacity=1.0, stroke_width=1.0, fill_color='#FFFFFF', fill_opacity=0.0)

Bases: object

A container for holding stroke and fill parameters for sVMobjects

stroke_color
Type

Color

stroke_opacity
Type

float

stroke_width
Type

float

fill_color
Type

Color

fill_opacity
Type

float

property fill_color
property stroke_color
class manimlib2.Render.Render

Bases: object

Render class to pair with the data classes.

Intended as an Abstract Base Class to define the Render interface

render(mobject, canvas)

Render the data onto the canvas.

Parameters
  • data – A reperesentation of the data for render to access

  • canvas – The canvas on which to render the data

  • transform_matrix (ndarray of floats) – A nxn matrix representing an affine transformation of the data to be applied prior to rendering

class manimlib2.Render.VRender(pen=None)

Bases: manimlib2.Render.CairoRender

Render Bezier curves into a pyCairo context.

pen
Type

Pen

fill_and_stroke(context, frame_height)

Apply the fill and stroke to the path.

Parameters

contexta pycairo context

The context on which to apply the stroke

property pen
render(mobject, camera)

Render the vmobject into the camera’s cairo context

Parameters
  • data (PolyBezier) –

  • context (Cairo Context) –

  • transform_matrix (3x3 ndarray) – The tranform matrix to apply to the context

manimlib2.Scene module

The main Manim Scene class.

Additional thoughts…

Scene is responsible for:

holding a set of Mobjects to be rendered

class manimlib2.Scene.Scene(camera)

Bases: object

add_mobject(key, mobject)

Add a Mobject to the scene

Parameters
  • key (dictionary key) – A key to the mobject for later reference by Instructions

  • mobject (Mobject) – The mobject to add

bring_to_top(key)

Move the mobject at key to the top of the z-order

property frame
get_mobject(key)
remove_mobject(key)

Remove a Mobject from the scene

Parameters

mobject (Mobject) – The mobject to remove

render()

Render the scene onto the camera frame

Parameters

camera (Camera instance) – An instance of the camera object

manimlib2.TexMobject module

Created on Thu Jul 23 09:03:08 2020

@author: Fred

class manimlib2.TexMobject.Number(number)

Bases: manimlib2.Mobject.CompositeMobject

update(number)
property value
class manimlib2.TexMobject.TexMath(text=None, pen=None)

Bases: manimlib2.TexMobject.Text

Use Tex to render some math

class manimlib2.TexMobject.Text(text=None, pen=None, pre='', post='')

Bases: manimlib2.Mobject.SVGMobject

Uses Tex to render some text

dvi_to_svg(dvi_file, regen_if_exists=False)
property opacity
set_pen(pen)
tex_to_dvi(tex_file)
class manimlib2.TexMobject.TextBox(text, text_pen=None, border_pen=None)

Bases: manimlib2.Mobject.CompositeMobject

property text_opacity

manimlib2.testutils module