|
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 | + |
22 | 88 | def __init__(
|
23 | 89 | self,
|
24 | 90 | mobject: Mobject,
|
| 91 | + angle: np.ndarray = TAU, |
25 | 92 | axis: np.ndarray = OUT,
|
26 |
| - radians: np.ndarray = TAU, |
27 | 93 | about_point: np.ndarray | None = None,
|
28 | 94 | about_edge: np.ndarray | None = None,
|
29 |
| - run_time: float = 5, |
| 95 | + run_time: float = 2, |
30 | 96 | rate_func: Callable[[float], float] = linear,
|
31 | 97 | **kwargs,
|
32 | 98 | ) -> None:
|
33 | 99 | self.axis = axis
|
34 |
| - self.radians = radians |
| 100 | + self.angle = angle |
35 | 101 | self.about_point = about_point
|
36 | 102 | self.about_edge = about_edge
|
37 | 103 | super().__init__(mobject, run_time=run_time, rate_func=rate_func, **kwargs)
|
38 | 104 |
|
39 | 105 | def interpolate_mobject(self, alpha: float) -> None:
|
40 | 106 | self.mobject.become(self.starting_mobject)
|
41 | 107 | self.mobject.rotate(
|
42 |
| - self.rate_func(alpha) * self.radians, |
| 108 | + self.rate_func(alpha) * self.angle, |
43 | 109 | axis=self.axis,
|
44 | 110 | about_point=self.about_point,
|
45 | 111 | about_edge=self.about_edge,
|
@@ -80,6 +146,10 @@ def construct(self):
|
80 | 146 | Rotate(Square(side_length=0.5), angle=2*PI, rate_func=linear),
|
81 | 147 | )
|
82 | 148 |
|
| 149 | + See also |
| 150 | + -------- |
| 151 | + :class:`~.Rotating`, :meth:`~.Mobject.rotate` |
| 152 | +
|
83 | 153 | """
|
84 | 154 |
|
85 | 155 | def __init__(
|
|
0 commit comments