[docs]classMVariable(MElement,Labelable):"""Manim Variable: a class for visualizing a variable using the Manim animation engine. Parameters ---------- value : Any The initial value of the variable to be displayed. style : :class:`MVariableStyle._DefaultStyle`, optional The style configuration to be applied to the variable. Defaults to ``MVariableStyle.DEFAULT``. """def__init__(self,value:Any,style:MVariableStyle._DefaultStyle=MVariableStyle.DEFAULT,):self.style=stylesuper().__init__(Rectangle(**self.style.square),Text(str(value),**self.style.value))
[docs]defadd_label(self,text:Text,direction:Vector3D=UP,buff:float=0.5,**kwargs,):"""Adds a label to the variable, positioned relative to its elements. Parameters ---------- text : :class:`~manim.mobject.text.text_mobject.Text` The text label to be added. direction : :class:`~manim.typing.Vector3D`, optional The direction in which to position the label. Default is ``UP``. buff : float, optional The buffer distance between the label and the element. Default is 0.5. **kwargs : Additional keyword arguments that are passed to the ``next_to()`` method of the underlying ``add_label`` method. Returns ------- self The instance of the :class:`MVariable` with the added label. """super().add_label(text,direction,buff,**kwargs)self+=self.labelreturnself