Skip to content

Commit f800288

Browse files
committed
Refactor Rotating, add docstring n See also, n adjust parameter
1 parent 82a186c commit f800288

File tree

2 files changed

+75
-5
lines changed

2 files changed

+75
-5
lines changed

docs/source/examples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ Animations
299299
path.become(previous_path)
300300
path.add_updater(update_path)
301301
self.add(path, dot)
302-
self.play(Rotating(dot, radians=PI, about_point=RIGHT, run_time=2))
302+
self.play(Rotating(dot, angle=PI, about_point=RIGHT, run_time=2))
303303
self.wait()
304304
self.play(dot.animate.shift(UP))
305305
self.play(dot.animate.shift(LEFT))

manim/animation/rotation.py

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,93 @@
1919

2020

2121
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+
2288
def __init__(
2389
self,
2490
mobject: Mobject,
91+
angle: np.ndarray = TAU,
2592
axis: np.ndarray = OUT,
26-
radians: np.ndarray = TAU,
2793
about_point: np.ndarray | None = None,
2894
about_edge: np.ndarray | None = None,
29-
run_time: float = 5,
95+
run_time: float = 2,
3096
rate_func: Callable[[float], float] = linear,
3197
**kwargs,
3298
) -> None:
99+
self.angle = angle
33100
self.axis = axis
34-
self.radians = radians
35101
self.about_point = about_point
36102
self.about_edge = about_edge
37103
super().__init__(mobject, run_time=run_time, rate_func=rate_func, **kwargs)
38104

39105
def interpolate_mobject(self, alpha: float) -> None:
40106
self.mobject.become(self.starting_mobject)
41107
self.mobject.rotate(
42-
self.rate_func(alpha) * self.radians,
108+
self.rate_func(alpha) * self.angle,
43109
axis=self.axis,
44110
about_point=self.about_point,
45111
about_edge=self.about_edge,
@@ -80,6 +146,10 @@ def construct(self):
80146
Rotate(Square(side_length=0.5), angle=2*PI, rate_func=linear),
81147
)
82148
149+
See also
150+
--------
151+
:class:`~.Rotating`, :meth:`~.Mobject.rotate`
152+
83153
"""
84154

85155
def __init__(

0 commit comments

Comments
 (0)