Animation that moves and rotates objects.
Class | Parameters | Explanation |
MoveAlongPath | mobject, path | Move mobject along the path |
Rotate | mobject, angle=PI, asis=OUT | Rotate mobject by angle about axis |
Rotating | mobject | Rotate mobject by radians about the axis |
TurnInsideOut | mobject | Flip mobject back and forth by path_arc=TAU/4 |
Animation classes related to move/rotating have different parameters used for each class, so each class will be explained.
MoveAlongPath class
object > Animation > MoveAlongPath
manimlib.animation.movement.MoveAlongPath(self, mobject, path, **kwargs)
Move mobject along the path
path = ArcBetweenPoints(LEFT*4+UP*2, RIGHT*4 + DOWN*2, angle=PI/2, stroke_width=8)
circle = Circle()
self.play(MoveAlongPath(circle, path), run_time=3)
CONFIG = {
"suspend_mobject_updating": False,
}
Parameters: mobject
Target object to be animated
Parameters: path
The object move along the path
Rotate class
object > Animation > Transform > Rotate
manimlib.animation.rotation.Rotateself, mobject, angle=PI, axis=OUT, **kwargs)
Rotate mobject by angle about axis.
'axis=OUT' is the default and OUT means the z-axis, so it rotates counterclockwise when the object is viewed from above.
When 'axis=LEFT/RIGHT', the object is rotated forward/backward.
self.play(Rotate(square, angle=PI/4), run_time=3) # 45 degrees, counterclockwise
self.play(Rotate(square, angle=380 * DEGREES, axis=RIGHT), run_time=3) # 380 degrees, backward
CONFIG = {
"about_point": None,
"about_edge": None,
}
Parameters: mobject
Target object to be animated
Parameters: angle=PI
The angle to rotate. unit is radians
Parameters: axis=OUT
Central axis of rotation.
If axis=OUT, it's z-axis: so the mobject rotates counterclockwise
when viewed from the front of the screen.
If axis=RIGHT, totates to the back of the screeen.
Parameters: **kwargs
CONFIG values of Rotate and Transform/Animation
Rotating class
object > Animation > Rotating
manimlib.animation.rotation.Rotating( mobject, **kwargs)
CONFIG = {
"axis": OUT,
"radians": TAU,
"run_time": 5,
"rate_func": linear,
"about_point": None,
"about_edge": None,
}
Rotate mobject by radians about the axis.
'axis=OUT' is the default and OUT means the z-axis, so it rotates counterclockwise when the object is viewed from above.
When 'axis=LEFT/RIGHT', the object is rotated forward/backward.
The Rotate and Rotating classes have similar uses.
The difference was that Rotating was implemented by inheriting Animation directly, and Rotate was created by inheriting Animation> Transform.
Therefore, if you are doing an animation that continuously rotates the circle in 1 degree increments, it is better to use Rotating than Rotate.
If you use Rotate class for this animation, the shape of circle may be distorted because Rotate class try to transform it from the previous object to new object simultaneously.
self.play(Rotating(square, radians=PI/4), run_time=3) #45 degrees, counterclockwise
self.play(Rotating(square, radians=380 * DEGREES, axis=RIGHT), run_time=3) #380 degrees, backward
Parameters: mobject
Target object to be animated
Parameters: **kwargs
CONFIG values of Rotate and Transform/Animation
Frequently used variables are,
- axis=OUT: Central axis of rotation.
If axis=OUT, it's z-axis: so the mobject rotates counterclockwise
when viewed from the front of the screen.
- radians=TAU: Angle to rotage. unit is radians
TrunInsideOut class
object > Animation > Transform > TurnInsideOut
manimlib.animation.indication.TurnInsideOut( mobject, **kwargs)
CONFIG = {
"path_arc": TAU / 4,
}
It has the effect of inverting mobject in front and back.
self.play(TurnInsideOut(square ), run_time=3)
Parameters: mobject
The target object to be animated
Parameters: **kwargs
CONFIG values of TurnInsideOut and Transform/Animation
Below is the code to test the move/rotation animation classes.
class MovingRotating(Scene):
def construct(self):
ani_classes = {
"MoveAlongPath": (MoveAlongPath,),
"Rotate": (Rotate,),
"Rotating": (Rotating,),
"TurnInsideOut": (TurnInsideOut,),
}
idx = 1
for name, ani in ani_classes.items():
if name == "MoveAlongPath" :
self.move_along_path(idx, name)
elif name == "Rotate":
self.rotate(idx, name)
elif name == "Rotating":
self.rotate(idx, name)
elif name == "TurnInsideOut":
self.turn_inside_out(idx, name)
self.wait()
idx += 1
def move_along_path(self,idx,ani_name):
name_text = Text(str(idx) + ". " + ani_name, stroke_width=0, size=0.4, color=YELLOW)
name_text.to_corner(UL)
arc = ArcBetweenPoints(LEFT*4+UP*2, RIGHT*4 + DOWN*2, angle=PI/2, stroke_width=8)
circle = Circle(color=YELLOW, fill_color=YELLOW, fill_opacity=0.6)
circle.move_to(arc.get_start())
self.add(name_text)
self.add(arc, circle)
self.wait()
self.play(MoveAlongPath(circle,arc), run_time=3)
self.remove(name_text, arc, circle)
def rotate(self, idx, ani_name):
name_text = Text(str(idx) + ". " + ani_name, stroke_width=0, size=0.4, color=YELLOW)
name_text.to_corner(UL)
square = Square()
self.add(name_text,square)
self.wait()
self.play(Rotate(square, angle=PI/4), run_time=3)
self.play(Rotate(square, angle=380 * DEGREES, axis=RIGHT), run_time=3)
self.wait()
self.remove(name_text,square)
def rotating(self, idx, ani_name):
name_text = Text(str(idx) + ". " + ani_name, stroke_width=0, size=0.4, color=YELLOW)
name_text.to_corner(UL)
square = Square()
self.add(name_text,square)
self.wait()
self.play(Rotating(square, radians=PI/4), run_time=3)
self.play(Rotating(square, radians=380 * DEGREES, axis=RIGHT), run_time=3)
self.wait()
self.remove(name_text, square)
def turn_inside_out(self, idx, ani_name):
name_text = Text(str(idx) + ". " + ani_name, stroke_width=0, size=0.4, color=YELLOW)
name_text.to_corner(UL)
square = Square()
self.add(name_text, square)
self.wait()
self.play(TurnInsideOut(square ), run_time=3)
self.wait()
Next: [06-1-E] Animation : Transformation series (1/3)
Go To: [99] Table of Contents
'Programming > Manim Lectures' 카테고리의 다른 글
[06-1-F] Animation : Transformation series (2/3) (0) | 2020.06.09 |
---|---|
[06-1-E] Animation : Transformation series (1/3) (0) | 2020.06.09 |
[06-1-C] Animation : Indicating series (0) | 2020.06.09 |
[06-1-B] Animation : Creation series (0) | 2020.06.09 |
[06-1-A] Animation Class and Rate Function (2) | 2020.06.09 |