Reference: Methods

What every object can do.

Placing

Each method changes the object at once and returns it, so they chain: Square().scale(2).set_color(BLUE).to_edge(LEFT). Put .animate in front to play the change instead: play(m.animate.shift(UP)).

  • .next_to(mobject_or_point, direction=RIGHT, buff=DEFAULT_MOBJECT_TO_MOBJECT_BUFFER, aligned_edge=ORIGIN): Puts it beside another object or point, edge to edge with a gap of buff.
  • .move_to(point_or_mobject, aligned_edge=ORIGIN, coor_mask=(1, 1, 1)): Moves its middle to a point, or onto another object.
  • .shift(*vectors): Moves it by an amount, such as RIGHT * 2.
  • .center(): Moves it to the middle of the picture.
  • .to_edge(edge=LEFT, buff=DEFAULT_MOBJECT_TO_EDGE_BUFFER): Puts it against an edge of the picture.
  • .to_corner(corner=DL, buff=DEFAULT_MOBJECT_TO_EDGE_BUFFER): Puts it in a corner of the picture.
  • .align_to(mobject_or_point, direction=ORIGIN): Lines up one of its edges with another object's, moving only that way.
  • .arrange(direction=RIGHT, buff=DEFAULT_MOBJECT_TO_MOBJECT_BUFFER, center=True, aligned_edge=ORIGIN): Puts its members in a row (RIGHT) or column (DOWN), centred where the group was.
  • .arrange_in_grid(rows=None, cols=None, buff=MED_SMALL_BUFF, cell_alignment=ORIGIN, flow_order="rd"): Puts its members in a grid, filling rows first.
  • .set_x(x, direction=ORIGIN): Moves it so its middle has this x.
  • .set_y(y, direction=ORIGIN): Moves it so its middle has this y.
  • .set_z(z, direction=ORIGIN): Moves it so its middle has this z.
from pymations import *

title = Text("Shapes").to_edge(UP)
row = VGroup(Circle(), Square()).arrange(RIGHT, buff=1).next_to(title, DOWN, buff=1)
add(title, row)

Size and turning

  • .scale(scale_factor, about_point=None, about_edge=None): Makes it bigger or smaller about its middle (or about_point); line widths stay the same.
  • .rotate(angle, axis=OUT, about_point=None): Turns it by an angle in radians about its middle (or about_point).
  • .flip(axis=UP): Mirrors it, left to right unless you give another axis.
  • .stretch(factor, dim): Stretches it along one direction only: 0 is x, 1 is y.
  • .scale_to_fit_width(width): Scales it until it is this wide.
  • .scale_to_fit_height(height): Scales it until it is this tall.
  • .stretch_to_fit_width(width): Stretches it to this width, changing its shape.
  • .stretch_to_fit_height(height): Stretches it to this height, changing its shape.
  • .match_width(mobject): Scales it to be as wide as another object.
  • .match_height(mobject): Scales it to be as tall as another object.
  • .width: How wide it is; set it to resize, keeping the shape.
  • .height: How tall it is; set it to resize, keeping the shape.

Colour and style

  • .set_color(color=YELLOW_C, family=True): Sets the outline and fill colour.
  • .set_fill(color=None, opacity=None, family=True): Sets the fill colour and how solid it is (opacity 0 to 1).
  • .set_stroke(color=None, width=None, opacity=None, background=False, family=True): Sets the outline's colour, width and opacity.
  • .set_opacity(opacity, family=True): Makes the whole object see-through (0) to solid (1).
  • .fade(darkness=0.5, family=True): Fades it by darkness (0.5 is half).
  • .set_color_by_gradient(*colors): Colours its members in steps through the colours given.
  • .set_z_index(z_index_value, family=True): Draws it above everything with a lower number.
  • .set_shadow(blur=0.15, offset=(0.05, -0.05), color=BLACK, opacity=0.5): Gives it a soft shadow (blur and offset in picture units). Pymations extra (not in Manim).
  • .set(): Sets several things at once: set(width=4, color=RED).
  • .get_color(): Its colour.

Where it is

These give points to place things with and do sums with. To print the numbers, await them (how).

  • .get_center() (also .get_center_of_mass): Its middle point.
  • .get_top(): The middle of its top edge.
  • .get_bottom(): The middle of its bottom edge.
  • .get_left(): The middle of its left edge.
  • .get_right(): The middle of its right edge.
  • .get_corner(direction) (also .get_critical_point, .get_edge_center, .get_boundary_point): A corner (UL, UR, DL, DR) or edge point.
  • .get_start(): Where its path starts (a line's first end).
  • .get_end(): Where its path ends (an arrow's tip).
  • .point_from_proportion(alpha): The point a proportion (0 to 1) of the way along its path.
  • .get_x(): The x of its middle.
  • .get_y(): The y of its middle.
  • .get_z(): The z of its middle.
  • .get_width(): How wide it is.
  • .get_height(): How tall it is.

Copies, members and saved looks

  • .animate: Put before any change to play it as a movement: m.animate.shift(UP); m.animate(run_time=2) sets its timing.
  • .copy(): A new, independent object just like it.
  • .become(mobject): Takes another object's shape, style and place.
  • .add(*mobjects): Puts more objects inside it.
  • .remove(*mobjects): Takes objects out of it.
  • .submobjects: The objects inside it, as a list.
  • .get_family(): It and everything inside it, as a list.
  • .save_state(): Remembers how it looks now, for Restore.
  • .restore(): Goes back to how it looked at save_state.
  • .generate_target(): Makes m.target, a copy to change; then MoveToTarget(m) plays the change.
from pymations import *

sq = Square()
add(sq)
sq.save_state()
play(sq.animate.scale(0.5).set_color(RED).shift(LEFT * 2))
play(Restore(sq))

Updaters

See Updaters for how they work.

  • .add_updater(update_function, index=None, call_updater=False): Runs a function on it every frame: f(m), or f(m, dt) with the time since the last frame.
  • .remove_updater(update_function): Takes one updater off.
  • .clear_updaters(recursive=True): Takes all its updaters off.
  • .suspend_updating(recursive=True): Pauses its updaters.
  • .resume_updating(recursive=True): Starts its updaters again.
  • .get_updaters(): Its updaters, as a list.
  • .has_updaters(): True if it has any.

Outline objects

  • .set_points_as_corners(points): Makes it a path with straight lines through the given points.
  • .set_points_smoothly(points): Makes it a smooth curve through the given points.
  • .get_length(): The length of its path (a value to await).
  • .get_angle(): The angle of a line, in radians (a value to await).