본문 바로가기

Programming/Manim code

(57)
[006]Example: Coordinate Methods Example 1 class CoordinateEx1(Scene): def construct(self): #1. create objects title = self.get_title() body = self.get_body() subtitle = self.get_subtitle() #2. locate objects title.move_to(ORIGIN).to_edge(UP, buff=1) body.next_to(title, DOWN, buff=1) subtitle.to_edge(DOWN, buff=0.5) #3. animate objects self.play(FadeIn(title), run_time=2) self.play(FadeIn(body), run_time=2) self.play(FadeIn(sub..
[005]mob.shift class ShiftTest(Scene): def construct(self): self.move_around_with_one_object() def move_around_with_one_object(self): dot = Dot() directions = [RIGHT, UP, LEFT, LEFT, DOWN, DOWN, RIGHT, RIGHT] self.add(dot) for d in directions: self.play(dot.shift, d) self.wait() self.remove(dot) class ShiftTest(Scene): def construct(self): self.make_latttice() def make_latttice(self): dot = Dot() directions = ..
[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,..
[003]mob.to_corner 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_c..
[002]mob.to_edge # based on the 'Scene' class def construct(self): self.to_edge_test() # self.to_edge_test(buff=0.5) def to_edge_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 [LEFT,RIGHT,UP,DOWN]: self.play(group.to_edge, d,..
[001]mob.move_to # based on the 'Scene' def construct(self): direction = [ORIGIN, LEFT, RIGHT, UP, DOWN] for d in direction: self.move_to_obj(d) def move_to_obj(self, direction): rect1 = Rectangle(width=0.4, height=0.2, stroke_color=RED) rect2 = Rectangle(width=1, height=1, stroke_color=BLUE).move_to(np.array([2, 3, 0])) self.add(rect1,rect2) self.wait() self.play(rect1.move_to, rect2, {"aligned_edge":direction}..
about I'm going to show video clips generated from the source code which is based on Python library, the Manim. Manim is an animation engine for creating math videos. (https://github.com/3b1b/manim) I'll just put some codes and the video clips generated from the code in the page. I thinkg it's enough to catch up how to make an animation with the Python code.