As we saw in the previous page, Manim can acess the screen position with (x,y,0) coordinates.
x has a value between [-7.1, 7.1] and y has a value between [-4.0, 4.0]
(x,y) coordinates can't be expressed with only one decimal place.
You can use up to the number of decimal places the float variable can represent, such as (1.54, 0.981)
The method to move an object to the coordinates positon on the screen is move_to.
Let's learn about the move_to method on this page.
move_to
maninlib.mobject.Mobject.move_to(point_or_mobject, aligned_edge=ORIGIN, coor_mask=np.array([1, 1, 1]))
Move a Mobject(Manim object) to certain screen postion or another Mobject's positon.
Parameters: point_or_mobject
point or Mobject to be moved. If it is a Mobject, move to Mobject's center position
Parameters: aligned_edge
Direction in which to base the object when moving.
If aligned_edge=LEFT, the moving object's left side touch the left side of the target object
It will be understood by referring to the figure in the descriptiion section below.
Parameters: coor_mask=np.array([1, 1, 1])
Coordinate sytem's mask value used when moving.
If the value is [0.5, 0.5, 0], moved to the half position of original destination.
Returns: self
The instance moved to the target postion.
Let's explain move_to functionality with a sample code.
move_to(tgt_obj, aligned_edge=LEFT/RIGHT/UP/DOWN)
The sample code move small rectangle to the target rectangle with aligned_edge.
rects[0].move_to(tgt_rect, aligned_edge=ORIGIN)
rects[1].move_to(tgt_rect, aligned_edge=LEFT)
rects[2].move_to(tgt_rect, aligned_edge=RIGHT)
rects[3].move_to(tgt_rect, aligned_edge=UP)
rects[4].move_to(tgt_rect, aligned_edge=DOWN)
The small rectangle of rect[0] - rect[4] move to the target rectangle.
rect[0].move_to(tgt_rect, aligned_edge=ORIGIN) is same with rect[0].move_to(tgt_rect) and it move the rect[0] to the center of the tgt_rect.
rects[1].move_to(tgt_rect, aligned_edge=LEFT) moves the rect[1] to the inside-left of the tgt_rect.
The rest of rect[2], rect[3] and rect[4] will also show how it moves along aligned_edge value.
The key point is 'object's left/right/up/down edge meets with the target's left/right/up/down edge'
aligned_edge= | action | ||
ORIGIN | obj's cener meet with tgt's center | ||
LEFT | obj's left edge meet with tgt's left edge | ||
RIGHT | obj's rigth edge meet with tgt's rigth edge | ||
UP | obj's up edge meet with tgt's up edge | ||
DOWN | obj's down edge meet with tgt's downedge |
The whole source code for the above sample is below. Please focus on how the move_to method is used in the code.
class MoveToTest2(Scene):
def construct(self):
rect = VGroup(*[Rectangle(width=0.3, height=0.2) for i in range(5)])
rect.to_edge(LEFT)
tgt_rect = Rectangle(width=3, height=3, color=YELLOW)
self.add(rect, tgt_rect)
self.wait()
rect[0].move_to(tgt_rect)
rect[1].move_to(tgt_rect, aligned_edge=LEFT)
rect[2].move_to(tgt_rect, aligned_edge=RIGHT)
rect[3].move_to(tgt_rect, aligned_edge=UP)
rect[4].move_to(tgt_rect, aligned_edge=DOWN)
self.wait()
If you saved above code as C:/now/manim/src/test.py. You can run this code in the PyCham by modifying Run/Debug Configuration like below screen shot. After that you can run the code by pressing 'Shift-F10'
move_to(tgt_obj, aligned_edge=LEFT/RIGHT/UP/DOWN)
Moving to the target point seems to a little different from the result to the target object, but the pricipal of 'LEFT edge meet with LEFT edge of the target' is not chaged.
Below is the code used for the above sample. At this point, focus on only about usage of 'move_to' method, and ignore the rest.
class MoveToTest3(Scene):
def construct(self):
rect = VGroup(*[Rectangle(width=0.3, height=0.2) for i in range(5)])
rect.to_edge(LEFT)
dot = Dot(color=YELLOW)
tgt_point = ORIGIN
self.add(rect, dot)
self.wait()
rect[0].move_to(tgt_point)
self.wait()
self.remove(rect[0])
rect[1].move_to(tgt_point, aligned_edge=LEFT)
self.wait()
self.remove(rect[1])
rect[2].move_to(tgt_point, aligned_edge=RIGHT)
self.wait()
self.remove(rect[2])
rect[3].move_to(tgt_point, aligned_edge=UP)
self.wait()
self.remove(rect[3])
rect[4].move_to(tgt_point, aligned_edge=DOWN)
self.wait()
self.remove(rect[4])
self.wait()
The 'move_to' method is frequently used method in the Manim. Therefore, you should be familiar with the method of use, but you only neet to remember two things.
- Use 'move_to' when you want to move an object to the point of the screen or another object's position
- The way to use 'aligned_edge' parameter
In the next page, we will learn about to_edge and to_corner, which are frequently used in addition to move_to.
[04-3] Move to absolute position(to_edge)
[04-4] Move to absolute position(to_corner)
Next: [04-3] Move to absolute position(to_edge)
Go To: [99] Table of Contents
'Programming > Manim Lectures' 카테고리의 다른 글
[04-4] Move to absolute position(to_corner) (0) | 2020.06.01 |
---|---|
[04-3] Move to absolute position(to_edge) (0) | 2020.06.01 |
[04-1]Coordinate System (0) | 2020.06.01 |
[04]Coordinate (0) | 2020.06.01 |
[03-6] Manim Components : Coordinate, Mobject, Animation) (0) | 2020.06.01 |