"""Animations related to rotation."""from__future__importannotations__all__=["Rotating","Rotate"]fromtypingimportTYPE_CHECKING,Callable,Sequenceimportnumpyasnpfrom..animation.animationimportAnimationfrom..animation.transformimportTransformfrom..constantsimportOUT,PI,TAUfrom..utils.rate_functionsimportlinearifTYPE_CHECKING:from..mobject.mobjectimportMobject
[docs]classRotate(Transform):"""Animation that rotates a Mobject. Parameters ---------- mobject The mobject to be rotated. angle The rotation angle. axis The rotation axis as a numpy vector. about_point The rotation center. about_edge If ``about_point`` is ``None``, this argument specifies the direction of the bounding box point to be taken as the rotation center. Examples -------- .. manim:: UsingRotate class UsingRotate(Scene): def construct(self): self.play( Rotate( Square(side_length=0.5).shift(UP * 2), angle=2*PI, about_point=ORIGIN, rate_func=linear, ), Rotate(Square(side_length=0.5), angle=2*PI, rate_func=linear), ) """def__init__(self,mobject:Mobject,angle:float=PI,axis:np.ndarray=OUT,about_point:Sequence[float]|None=None,about_edge:Sequence[float]|None=None,**kwargs,)->None:if"path_arc"notinkwargs:kwargs["path_arc"]=angleif"path_arc_axis"notinkwargs:kwargs["path_arc_axis"]=axisself.angle=angleself.axis=axisself.about_edge=about_edgeself.about_point=about_pointifself.about_pointisNone:self.about_point=mobject.get_center()super().__init__(mobject,path_arc_centers=self.about_point,**kwargs)defcreate_target(self)->Mobject:target=self.mobject.copy()target.rotate(self.angle,axis=self.axis,about_point=self.about_point,about_edge=self.about_edge,)returntarget