More Complex Animations

At their most fundamental, animations built with ManimLib2 consist of instructions that modify the attributes of Mobjects. For example, the Move and MoveTo instructions modify the position attribute of the Mobject assigned to them. Most instructions, Move and MoveTo included, inherit from one of two core instructions; SetAttribute and AdjustAttribute. Complex animations can be created by creating classes that inherit from one of the Mobject classes, defining custom attributes that control their appearance, and maniuplating those attributes with either SetAttribute or AdjustAttribute.

AdjustAttribute

Here’s the docstring for AdjustAttribute:

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.