How manim-eng works

This is not going to be an explanation of how Manim works. Manim has its own guide for that. Rather, this is intended as a narrative guide to the base classes that manim-eng adds to implement its basic additional functionality.

The Mark class

The Mark class is used for all of manim-eng’s textual labels (i.e. labels, annotations, current labels, and voltage labels), which are referred to by the umbrella term marks. It is a thin wrapper around Manim’s MathTex object, which adds a few new capabilities.

In particular, it allows the displayed mathematical text to be updated on the fly using its set_text() method, and implements functionality for automatically positioning the mark relative two a set of two anchors.

Anchors

Marks hold references to two anchors: a centre_reference and an anchor. Marks are then positioned next to anchor on the opposite side to centre_reference using an updater.

Stealing a visualisation from Marks remain upright and enabling debug mode, we can see this graphically.

The purple centre anchor in the middle is the centre_reference and the red label anchor is the anchor for the label mark with the text R. The R is kept with one edge next to its anchor while staying opposite the centre_reference. In practice, this means that the R is kept in the most logical position to place it when drawing a circuit symbol.

Anchors are implemented using the very simple Anchor base class and specialisations for each anchor type (see anchor). Their position is accessed using the pos property.

The Markable class

The Markable class is the abstract base class of almost all manim-eng mobjects. Its purpose is to add the functionality required to be able to attach marks to mobjects and have them be rotationally invariant. To see what I mean by this, consider the rotating resistor above, and note that the R does not rotate, despite being owned by the resistor mobject.

To achieve this, each markable maintains two private VGroups, __marks and __rotate. All rotation operations are then overloaded to apply just to the __rotate group, and the standard operations of add(), add_to_back(), and remove() are then overloaded to automatically sort marks into the __marks group and everything else into __rotate.

Markable also provides protected methods for managing marks: _set_mark() and _clear_mark(). These take a reference to the mark to modify and, in the _set_mark() case, the mark text to set, and handle managing mark visibilities and updates. However, it is up to the implementing class to construct marks and the anchors they attach to.

Important

The implementing class does not need to worry about add()-ing or remove()-ing marks, as this is handled by _set_mark() and _clear_mark(). It does however need to add anchors (though in most cases manim-eng has handled this for you, as chances are you’re subclassing Component, which sets anchors up automatically.

There are also, of course, animation overrides for all added methods.