본문 바로가기

Programming/Manim Lectures

[04-4] Move to absolute position(to_corner)

반응형

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)

 

[04-5] Move to relative position(next_to)

In the previous page, we looked at the 'to_move', 'to_edge' and 'to_corner' method to send an object to the promised position, or absolute position. From this page, we will look at the 'next_to' and..

infograph.tistory.com

Go To: [99] Table of Contents

 

 

반응형