Component¶
- class manim_eng.components.base.component.Component(terminals: list[Terminal], label: str | Value | None = None, annotation: str | Value | None = None, **kwargs: Any)¶
Bases:
MarkableBase 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
Valueto be typeset as a math mode string.annotation (str | Value | None, optional) –
- An annotation to set. Takes a TeX math mode string, or a
Valueto be typeset as a math mode string.
- An annotation to set. Takes a TeX math mode string, or a
Attributes
Component.animateUsed to animate the application of any method of
self.Component.animation_overridesComponent.colorComponent.depthThe depth of the mobject.
Component.fill_colorIf there are multiple colors (for gradient) this returns the first one
Component.heightThe height of the mobject.
Component.n_points_per_curveComponent.sheen_factorComponent.stroke_colorThe list of terminals of the component.
Component.widthThe 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 baseComponentclass 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
directionsuch that the line between the end ofself_terminalandotherhas direction vectordirection.- Parameters:
self_terminal (Terminal | str) – Either a
Terminalbelonging 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
Terminalbelonging to another component, aNode, aMonopole(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
Terminalpassed toself_terminaldoes not belong to this component.AttributeError – If a string passed to
self_terminaldoes not represent an existing attribute on this component.ValueError – If a string passed to
self_terminaldoes not represent an attribute of this component that produces aTerminalinstance.ValueError – If
otherbelongs to this component (if it is aTerminal) or ifotheris this component (if it is aNodeorMonopole).
Notes
In geometric terms, the component in moved such that the end of
self_terminalis at the intersection of the lines that- Have direction vector perpendicular to
directionand go through the current position of the end of
self_terminal; and
- Have direction vector perpendicular to
- Have direction vector
directionand go through the end of other(in the case that it is aTerminal) or throughother(in the case that it is a point).
- Have direction vector
- 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
Terminalbelonging 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
Terminalpassed toterminaldoes not belong to this component.AttributeError – If a string passed to
terminaldoes not represent an existing attribute.ValueError – If a string passed to
terminaldoes not represent an attribute of this component that produces aTerminalinstance.
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
Valueto be typeset as a math mode string.terminal (Terminal | str | None) – Either a
Terminalbelonging 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
Terminalpassed toterminaldoes not belong to this component.AttributeError – If a string passed to
terminaldoes not represent an existing attribute.ValueError – If a string passed to
terminaldoes not represent an attribute of this component that produces aTerminalinstance.
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
Valueto 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
Valueto be typeset as a math mode string.terminal (Terminal | str, optional) – Either a
Terminalbelonging 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
Terminalpassed toterminaldoes not belong to this component.AttributeError – If a string passed to
terminaldoes not represent an existing attribute.ValueError – If a string passed to
terminaldoes not represent an attribute of this component that produces aTerminalinstance.
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
Valueto be typeset as a math mode string.
See also
units.Value
- 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
Voltageobject. This method automatically sets the component is it called upon in theavoidargument ofVoltage(and as such overrides this argument).- Parameters:
start (Terminal | str) – Either a
Terminalbelonging to this component, or a string representing an attribute of this component that returns a terminal (e.g."right").end (Terminal | str) – Either a
Terminalbelonging 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
Voltageconstructor.**kwargs – Keyword arguments to be passed to the
Voltageconstructor. Any keyword argument with the keyavoidwill be ignored.
- Returns:
The voltage arrow resulting from the specification given.
- Return type:
- Raises:
ValueError – If a passed
Terminaldoes 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
Terminalinstance.ValueError – If the terminals specified for both
startandendare the same.