Component

class manim_eng.components.base.component.Component(terminals: list[Terminal], label: str | Value | None = None, annotation: str | Value | None = None, **kwargs: Any)

Bases: Markable

Base class for all components.

Parameters:
  • terminals (list[Terminal]) – The terminals of the component. Management of terminal visibility is handled by the constructor; terminals should not be added before or after they are passed to this constructor.

  • label (str | Value | None, optional) – A label to set. Takes a TeX math mode string, or a Value to be typeset as a math mode string.

  • annotation (str | Value | None, optional) –

    An annotation to set. Takes a TeX math mode string, or a Value to be typeset

    as a math mode string.

Attributes

Component.animate

Used to animate the application of any method of self.

Component.animation_overrides

Component.color

Component.depth

The depth of the mobject.

Component.fill_color

If there are multiple colors (for gradient) this returns the first one

Component.height

The height of the mobject.

Component.n_points_per_curve

Component.sheen_factor

Component.stroke_color

Component.terminals

The list of terminals of the component.

Component.width

The width of the mobject.

_construct() None

Construct the shape of the component.

Code to build the component’s symbol goes in here and not in __init__() (contrary to Manim’s standard). This is because the base Component class has to perform initialisation both before (to set up the groups etc.) and after (to set the anchor positions for annotations) the component’s shape setup.

align_terminal(self_terminal: Terminal | str, other: Terminal | mnt.Point3D | Node | Monopole, direction: mnt.Vector3D | None = None) Self

Align a component terminal with a point or another component.

Moves this component along the line perpendicular to direction such that the line between the end of self_terminal and other has direction vector direction.

Parameters:
  • self_terminal (Terminal | str) – Either a Terminal belonging to this component, or a string representing an attribute of this component that returns a terminal (e.g. "right").

  • other (Terminal | Point3D | Node | Monopole) – A Terminal belonging to another component, a Node, a Monopole (for which its single terminal is selected), or a point in space.

  • direction (Vector3D | None) – The direction to align the terminals in. If not supplied, uses self_terminal’s direction.

Raises:
  • ValueError – If a Terminal passed to self_terminal does not belong to this component.

  • AttributeError – If a string passed to self_terminal does not represent an existing attribute on this component.

  • ValueError – If a string passed to self_terminal does not represent an attribute of this component that produces a Terminal instance.

  • ValueError – If other belongs to this component (if it is a Terminal) or if other is this component (if it is a Node or Monopole).

Notes

In geometric terms, the component in moved such that the end of self_terminal is at the intersection of the lines that

  • Have direction vector perpendicular to direction and go through the

    current position of the end of self_terminal; and

  • Have direction vector direction and go through the end of

    other (in the case that it is a Terminal) or through other (in the case that it is a point).

clear_annotation() Self

Clear the annotation of the component.

clear_current(terminal: Terminal | str | None = None) Self

Clear the current label on one of the terminals of the component.

Parameters:

terminal (Terminal | str | None) – Either a Terminal belonging to this component, or a string representing an attribute of this component that returns a component (e.g. "right"). If unspecified, defaults to the first terminal in the internal terminal list. In the case of monopoles, this is the only terminal, and in the case of bipoles, this is the left terminal.

Raises:
  • ValueError – If a Terminal passed to terminal does not belong to this component.

  • AttributeError – If a string passed to terminal does not represent an existing attribute.

  • ValueError – If a string passed to terminal does not represent an attribute of this component that produces a Terminal instance.

See also

components.base.terminal.Terminal.clear_current

clear_label() Self

Clear the label of the component.

get_center() ndarray[tuple[Any, ...], dtype[float64]]

Get the centre of the components.

This is not necessarily the exact centre of the box the component symbol occupies. It is rather the point about which it is most logical to rotate the component. For bipoles, it will be at the midpoint of the line between the two terminals.

Returns:

The centre of the components.

Return type:

Point3D

reset_current(label: str | Value, terminal: Terminal | str | None = None, **kwargs: Any) Self

Reset the current label on one of the terminals of the component.

Warning: Using this will reset all unspecified arguments to their default values. See the documentation of Terminal.reset_current() for more information.

Parameters:
  • label (str | Value) – The current label to set. Takes a TeX math mode string, or a Value to be typeset as a math mode string.

  • terminal (Terminal | str | None) – Either a Terminal belonging to this component, or a string representing an attribute of this component that returns a component (e.g. "right"). If unspecified, defaults to the first terminal in the internal terminal list. In the case of monopoles, this is the only terminal, and in the case of bipoles, this is the left terminal.

  • **kwargs (Any) – Kwargs to pass on to the terminal’s .set_current() method.

Raises:
  • ValueError – If a Terminal passed to terminal does not belong to this component.

  • AttributeError – If a string passed to terminal does not represent an existing attribute.

  • ValueError – If a string passed to terminal does not represent an attribute of this component that produces a Terminal instance.

See also

components.base.terminal.Terminal.reset_current

set_annotation(annotation: str | Value) Self

Set the annotation of the component.

Parameters:

annotation (str | Value) – The annotation to set. Takes a TeX math mode string, or a Value to be typeset as a math mode string.

See also

units.Value

set_current(label: str | Value | None, terminal: Terminal | str | None = None, **kwargs: Any) Self

Set the current label on one of the terminals of the component.

Parameters:
  • label (str | Value, optional) – The current label to set. Takes a TeX math mode string, or a Value to be typeset as a math mode string.

  • terminal (Terminal | str, optional) – Either a Terminal belonging to this component, or a string representing an attribute of this component that returns a component (e.g. "right"). If unspecified, defaults to the first terminal in the internal terminal list. In the case of monopoles, this is the only terminal, and in the case of bipoles, this is the left terminal.

  • **kwargs (Any) – Kwargs to pass on to the terminal’s .set_current() method.

Raises:
  • ValueError – If a Terminal passed to terminal does not belong to this component.

  • AttributeError – If a string passed to terminal does not represent an existing attribute.

  • ValueError – If a string passed to terminal does not represent an attribute of this component that produces a Terminal instance.

See also

components.base.terminal.Terminal.set_current

set_label(label: str | Value) Self

Set the label of the component.

Parameters:

label (str | Value) – The label to set. Takes a TeX math mode string, or a Value to be typeset as a math mode string.

See also

units.Value

property terminals: list[Terminal]

The list of terminals of the component.

voltage(start: Terminal | str, end: Terminal | str, *args: Any, **kwargs: Any) Voltage

Return a voltage arrow across the component.

Convenience method for creating a voltage arrow across two terminals of this component. Returns the created Voltage object. This method automatically sets the component is it called upon in the avoid argument of Voltage (and as such overrides this argument).

Parameters:
  • start (Terminal | str) – Either a Terminal belonging to this component, or a string representing an attribute of this component that returns a terminal (e.g. "right").

  • end (Terminal | str) – Either a Terminal belonging to this component, or a string representing an attribute of this component that returns a terminal (e.g. "left").

  • *args – Positional arguments to be passed to the Voltage constructor.

  • **kwargs – Keyword arguments to be passed to the Voltage constructor. Any keyword argument with the key avoid will be ignored.

Returns:

The voltage arrow resulting from the specification given.

Return type:

Voltage

Raises:
  • ValueError – If a passed Terminal does not belong to this component.

  • AttributeError – If a string passed for either terminal does not represent an existing attribute.

  • ValueError – If a string passed for either terminal does not represent an attribute of this component that produces a Terminal instance.

  • ValueError – If the terminals specified for both start and end are the same.