In the previous chapter, we looked at the to_edge that moves to the left/right/up/down direction of the screen. A similar method is to_corner. Move the object to the corner of the screen.
For example, if you want to place your own logo on the bottom right of the screen when creating a video, you can say logo.to_corner(DR, buff=0.3).
Here, the value of DR=DOWN+RIGHT points to the right side of the bottom of the screen. The buff determines how far away from the corner.
to_corner
manimlib.mobject.Mobject.to_corner(corner=LEFT + DOWN, buff=DEFAULT_MOBJECT_TO_EDGE_BUFFER)
Moves the object to the corner of the screen specified in 'corner' parameter. Here, how far away from the corner is determined by the buff value.
Parameters: corner=LEFT + DOWN
It indicates which side to move to,
and UL/UR/DL/DR or UP+LEFT / UP + RIGHT / DOWN + LEFT / DOWN + RIGHT values are used.
Parameters: buff=DEFAULT_MOBJECT_TO_EDGE_BUFFER
A value that determines how far away from the edge of the screen.
DEFAULT_MOBJECT_TO_EDGE_BUFFER = 0.5 by default
Returns: self
Object instance moved to the corner of the screen
Let's look up the code using 'to_corner'.
Similar to the 'to_edge' example in the previous page, this is an animation of grouping rectangle and text together and moving the group from the center of the screen to the top-left/top-right/bottom-left/bottom-right corners.
class ToCornerTest(Scene):
def construct(self):
self.draw_border()
self.to_corner_test()
self.to_corner_test(buff=0.5)
def draw_border(self):
border = Rectangle(width=FRAME_WIDTH, height=FRAME_HEIGHT, stroke_color=YELLOW)
self.add(border)
def to_corner_test(self, buff=0):
text = Text("Hello", font='Arial', stroke_width=1, size=0.4)
rect = Rectangle(width=0.3, height=text.get_height(),stroke_color=RED)
group = VGroup(rect,text).arrange(RIGHT)
group.save_state()
self.add(group)
for d in [UL,UR,DL,DR]:
self.play(group.to_edge, d, {"buff":buff})
self.wait()
group.restore()
self.remove(group)
Next : [04-5] Move to relative position(next_to)
Go To: [99] Table of Contents
'Programming > Manim Lectures' 카테고리의 다른 글
[04-6] Move to relative position(shift) (0) | 2020.06.01 |
---|---|
[04-5] Move to relative position(next_to) (0) | 2020.06.01 |
[04-3] Move to absolute position(to_edge) (0) | 2020.06.01 |
[04-2] Move to absolute position(move_to) (0) | 2020.06.01 |
[04-1]Coordinate System (0) | 2020.06.01 |