Let's make a simple animation showing the movement of a shape using to_edge and to_corner. The first screen is a dot on the left side, and this dot flies up/center/bottom of the wall on the right side.
It's a simple animation, but if you follow the whole process of how to make a coding strategy for how to write these programming needs, and how to do the actual coding and execution, it will be a cornerstone for making complex animations without problems.
Let's make a plan how to code for the requirement.
1) Make a single Dot object and move it to the left side: dot.to_edge(LEFT)
2) Since this dot has to fly to 3 places, we need to make 3 copies of the Dot object.
3) You can send the three copied Dots using to_corner(UR), to_edge(RIGHT) and to_corner(DR).
4) We will make the above 2)~3) process as a method so that we can call it multiple times.
Let's create code according to the above strategy.
1) Make a single Dot object and move it to the left side: dot.to_edge(LEFT)
dot = Dot()
dot.to_edge(LEFT)
self.add(dot)
self.wait()
2) Since this dot has to fly to 3 places, we need to make 3 copies of the Dot object.
d1 = dot.copy()
d2 = dot.copy()
d3 = dot.copy()
3) You can send the three copied Dots using to_corner(UR), to_edge(RIGHT) and to_corner(DR).
self.play(
d1.to_corner, UR,
d2.to_edge, RIGHT,
d3.to_corner, DR,
)
4) We will make the above 2)~3) process as a method so that we can call it multiple times.
def move_dot(self, dot):
d1 = dot.copy()
d2 = dot.copy()
d3 = dot.copy()
self.play(
d1.to_corner, UR,
d2.to_edge, RIGHT,
d3.to_corner, DR,
)
self.remove(d1, d2, d3)
Below is full source code.
from manimlib.imports import *
class CoordinateEx2(Scene):
def construct(self):
dot = Dot()
dot.to_edge(LEFT)
self.add(dot)
self.wait()
for i in range(0,5):
self.move_dot(dot)
def move_dot(self, dot):
d1 = dot.copy()
d2 = dot.copy()
d3 = dot.copy()
self.play(
d1.to_corner, UR,
d2.to_edge, RIGHT,
d3.to_corner, DR,
)
self.remove(d1, d2, d3)
Next : [05]Mobject
Go To: [99] Table of Contents
'Programming > Manim Lectures' 카테고리의 다른 글
[05-1]Common methods of Mobject (0) | 2020.06.05 |
---|---|
[05]Mobject (0) | 2020.06.05 |
[04-6] Move to relative position(shift) (0) | 2020.06.01 |
[04-5] Move to relative position(next_to) (0) | 2020.06.01 |
[04-4] Move to absolute position(to_corner) (0) | 2020.06.01 |