본문 바로가기

Programming/Manim code

[004]mob.next_to

반응형

1. next_to(obj, ORIGIN/LEFT/RIGHT/UP/DOWN/UL/UR/DL/DR)

class NextToTest(Scene):
    def construct(self):
        dir_str = ['ORIGIN', 'LEFT', 'RIGHT', 'UP', 'DOWN', 'UL', 'UR', 'DL', 'DR']
        dir_list = [ORIGIN, LEFT, RIGHT, UP, DOWN, UL, UR, DL, DR]

        #1. next_to(obj, ORIGIN/LEFT/RIGHT/UP/DOWN/UL/UR/DL/DR)
        for str, d in zip(dir_str, dir_list):
            self.next_to_obj(str,d)
            
    def next_to_obj(self, str, direction=ORIGIN, buff=0, aligned_edge=ORIGIN):
        rect1 = Rectangle(width=0.4, height=0.2, stroke_color=RED)
        rect2 = Rectangle(width=1.5, height=1.5, stroke_color=BLUE).move_to(np.array([2, 2, 0]))
        text = Text(str, font='굴림', stroke_width=0, size=0.4).next_to(rect1, DOWN)

        self.add(rect1, rect2, text)
        self.wait(0.3)

        self.play(rect1.next_to, rect2, direction, {"buff":buff, "aligned_edge": aligned_edge})
        self.wait()
        self.remove(rect1, rect2, text)            

 

 


 

2. next_to(obj, direction, buff=0.5)

class NextToTest(Scene):
    def construct(self):
        dir_str = ['ORIGIN', 'LEFT', 'RIGHT', 'UP', 'DOWN', 'UL', 'UR', 'DL', 'DR']
        dir_list = [ORIGIN, LEFT, RIGHT, UP, DOWN, UL, UR, DL, DR]
        
        #2. next_to(obj, direction, buff=0.5)
        for str, d in zip(dir_str, dir_list):
            self.next_to_obj(str+" buff=0.5",d, buff=0.5)      
            
    def next_to_obj(self, str, direction=ORIGIN, buff=0, aligned_edge=ORIGIN):
        rect1 = Rectangle(width=0.4, height=0.2, stroke_color=RED)
        rect2 = Rectangle(width=1.5, height=1.5, stroke_color=BLUE).move_to(np.array([2, 2, 0]))
        text = Text(str, font='굴림', stroke_width=0, size=0.4).next_to(rect1, DOWN)

        self.add(rect1, rect2, text)
        self.wait(0.3)

        self.play(rect1.next_to, rect2, direction, {"buff":buff, "aligned_edge": aligned_edge})
        self.wait()
        self.remove(rect1, rect2, text)            

 


3. next_to(obj, LEFT, buff=0, aligned_edge=ORIGIN/LEFT/RIGHT/UP/DOWN

class NextToTest(Scene):
    def construct(self):
        dir_str = ['ORIGIN', 'LEFT', 'RIGHT', 'UP', 'DOWN', 'UL', 'UR', 'DL', 'DR']
        dir_list = [ORIGIN, LEFT, RIGHT, UP, DOWN, UL, UR, DL, DR]
        
        #3. next_to(obj, LEFT, buff=0, aligned_edge=ORIGIN/LEFT/RIGHT/UP/DOWN
        for i in range(0,5):
            self.next_to_obj("LEFT, aligned_edge="+dir_str[i], LEFT, buff=0, aligned_edge=dir_list[i])        
            
    def next_to_obj(self, str, direction=ORIGIN, buff=0, aligned_edge=ORIGIN):
        rect1 = Rectangle(width=0.4, height=0.2, stroke_color=RED)
        rect2 = Rectangle(width=1.5, height=1.5, stroke_color=BLUE).move_to(np.array([2, 2, 0]))
        text = Text(str, font='굴림', stroke_width=0, size=0.4).next_to(rect1, DOWN)

        self.add(rect1, rect2, text)
        self.wait(0.3)

        self.play(rect1.next_to, rect2, direction, {"buff":buff, "aligned_edge": aligned_edge})
        self.wait()
        self.remove(rect1, rect2, text)            

 


4 next_to(obj, LEFT, buff=0.5, aligned_edge=ORIGIN/LEFT/RIGHT/UP/DOWN

class NextToTest(Scene):
    def construct(self):
        dir_str = ['ORIGIN', 'LEFT', 'RIGHT', 'UP', 'DOWN', 'UL', 'UR', 'DL', 'DR']
        dir_list = [ORIGIN, LEFT, RIGHT, UP, DOWN, UL, UR, DL, DR]

        # 4 next_to(obj, LEFT, buff=0.5, aligned_edge=ORIGIN/LEFT/RIGHT/UP/DOWN
        for i in range(0, 5):
            self.next_to_obj("LEFT, buff=0.5, aligned_edge=" + dir_str[i], LEFT, buff=0.5, aligned_edge=dir_list[i])

    def next_to_obj(self, str, direction=ORIGIN, buff=0, aligned_edge=ORIGIN):
        rect1 = Rectangle(width=0.4, height=0.2, stroke_color=RED)
        rect2 = Rectangle(width=1.5, height=1.5, stroke_color=BLUE).move_to(np.array([2, 2, 0]))
        text = Text(str, font='굴림', stroke_width=0, size=0.4).next_to(rect1, DOWN)

        self.add(rect1, rect2, text)
        self.wait(0.3)

        self.play(rect1.next_to, rect2, direction, {"buff":buff, "aligned_edge": aligned_edge})
        self.wait()
        self.remove(rect1, rect2, text)

 


5. next_to(point, ORIGIN/LEFT/RIGHT/UP/DOWN/UL/UR/DL/DR)

class NextToTest(Scene):
    def construct(self):
        dir_str = ['ORIGIN', 'LEFT', 'RIGHT', 'UP', 'DOWN', 'UL', 'UR', 'DL', 'DR']
        dir_list = [ORIGIN, LEFT, RIGHT, UP, DOWN, UL, UR, DL, DR]

        # 5. next_to(point, ORIGIN/LEFT/RIGHT/UP/DOWN/UL/UR/DL/DR)
        for str, d in zip(dir_str, dir_list):
            self.next_to_point(str,d)

    def next_to_point(self, str, direction=ORIGIN, buff=0, aligned_edge=ORIGIN):
        rect1 = Rectangle(width=0.4, height=0.2, stroke_color=RED)
        rect2 = Rectangle(width=1.5, height=1.5, stroke_color=BLUE).move_to(np.array([2, 2, 0]))
        text = Text(str, font='굴림', stroke_width=0, size=0.4).next_to(rect1, DOWN)

        tgt_point = np.array([2,2,0])

        self.add(rect1, rect2, text)
        self.wait(0.3)

        self.play(rect1.next_to, tgt_point, direction, {"buff": buff, "aligned_edge": aligned_edge})
        self.wait()
        self.remove(rect1, rect2, text)

 

 

반응형

'Programming > Manim code' 카테고리의 다른 글

[006]Example: Coordinate Methods  (0) 2020.05.05
[005]mob.shift  (0) 2020.05.05
[003]mob.to_corner  (0) 2020.05.05
[002]mob.to_edge  (0) 2020.05.05
[001]mob.move_to  (0) 2020.05.05