|
19 | 19 |
|
20 | 20 |
|
21 | 21 | class Rotating(Animation): |
22 | | - """Animation that rotates a Mobject. |
23 | | -
|
24 | | - Parameters |
25 | | - ---------- |
26 | | - mobject |
27 | | - The mobject to be rotated. |
28 | | - angle |
29 | | - The rotation angle in radians. Predefined constants such as ``DEGREES`` |
30 | | - can also be used to specify the angle in degrees. |
31 | | - axis |
32 | | - The rotation axis as a numpy vector. |
33 | | - about_point |
34 | | - The rotation center. |
35 | | - about_edge |
36 | | - If ``about_point`` is ``None``, this argument specifies |
37 | | - the direction of the bounding box point to be taken as |
38 | | - the rotation center. |
39 | | - run_time |
40 | | - The duration of the animation in seconds. |
41 | | - rate_func |
42 | | - The function defining the animation progress based on the relative |
43 | | - runtime (see :mod:`~.rate_functions`) . |
44 | | - **kwargs |
45 | | - Additional keyword arguments passed to :class:`~.Animation`. |
46 | | -
|
47 | | - Examples |
48 | | - -------- |
49 | | - .. manim:: RotatingDemo |
50 | | -
|
51 | | - class RotatingDemo(Scene): |
52 | | - def construct(self): |
53 | | - circle = Circle(radius=1, color=BLUE) |
54 | | - line = Line(start=ORIGIN, end=RIGHT) |
55 | | - arrow = Arrow(start=ORIGIN, end=RIGHT, buff=0, color=GOLD) |
56 | | - vg = VGroup(circle,line,arrow) |
57 | | - self.add(vg) |
58 | | - anim_kw = {"about_point": arrow.get_start(), "run_time": 1} |
59 | | - self.play(Rotating(arrow, 180*DEGREES, **anim_kw)) |
60 | | - self.play(Rotating(arrow, PI, **anim_kw)) |
61 | | - self.play(Rotating(vg, PI, about_point=RIGHT)) |
62 | | - self.play(Rotating(vg, PI, axis=UP, about_point=ORIGIN)) |
63 | | - self.play(Rotating(vg, PI, axis=RIGHT, about_edge=UP)) |
64 | | - self.play(vg.animate.move_to(ORIGIN)) |
65 | | -
|
66 | | - .. manim:: RotatingDifferentAxis |
67 | | -
|
68 | | - class RotatingDifferentAxis(ThreeDScene): |
69 | | - def construct(self): |
70 | | - axes = ThreeDAxes() |
71 | | - cube = Cube() |
72 | | - arrow2d = Arrow(start=[0, -1.2, 1], end=[0, 1.2, 1], color=YELLOW_E) |
73 | | - cube_group = VGroup(cube,arrow2d) |
74 | | - self.set_camera_orientation(gamma=0, phi=40*DEGREES, theta=40*DEGREES) |
75 | | - self.add(axes, cube_group) |
76 | | - play_kw = {"run_time": 1.5} |
77 | | - self.play(Rotating(cube_group, PI), **play_kw) |
78 | | - self.play(Rotating(cube_group, PI, axis=UP), **play_kw) |
79 | | - self.play(Rotating(cube_group, 180*DEGREES, axis=RIGHT), **play_kw) |
80 | | - self.wait(0.5) |
81 | | -
|
82 | | - See also |
83 | | - -------- |
84 | | - :class:`~.Rotate`, :meth:`~.Mobject.rotate` |
85 | | -
|
86 | | - """ |
87 | | - |
88 | 22 | def __init__( |
89 | 23 | self, |
90 | 24 | mobject: Mobject, |
91 | | - angle: np.ndarray = TAU, |
92 | 25 | axis: np.ndarray = OUT, |
| 26 | + radians: np.ndarray = TAU, |
93 | 27 | about_point: np.ndarray | None = None, |
94 | 28 | about_edge: np.ndarray | None = None, |
95 | | - run_time: float = 2, |
| 29 | + run_time: float = 5, |
96 | 30 | rate_func: Callable[[float], float] = linear, |
97 | 31 | **kwargs, |
98 | 32 | ) -> None: |
99 | 33 | self.axis = axis |
100 | | - self.angle = angle |
| 34 | + self.radians = radians |
101 | 35 | self.about_point = about_point |
102 | 36 | self.about_edge = about_edge |
103 | 37 | super().__init__(mobject, run_time=run_time, rate_func=rate_func, **kwargs) |
104 | 38 |
|
105 | 39 | def interpolate_mobject(self, alpha: float) -> None: |
106 | 40 | self.mobject.become(self.starting_mobject) |
107 | 41 | self.mobject.rotate( |
108 | | - self.rate_func(alpha) * self.angle, |
| 42 | + self.rate_func(alpha) * self.radians, |
109 | 43 | axis=self.axis, |
110 | 44 | about_point=self.about_point, |
111 | 45 | about_edge=self.about_edge, |
@@ -146,10 +80,6 @@ def construct(self): |
146 | 80 | Rotate(Square(side_length=0.5), angle=2*PI, rate_func=linear), |
147 | 81 | ) |
148 | 82 |
|
149 | | - See also |
150 | | - -------- |
151 | | - :class:`~.Rotating`, :meth:`~.Mobject.rotate` |
152 | | -
|
153 | 83 | """ |
154 | 84 |
|
155 | 85 | def __init__( |
|
0 commit comments