본문 바로가기

분류 전체보기

(284)
[010]save_state/restore class RestoreTest(Scene): def construct(self): dot = Dot() dot.save_state() self.add(dot) self.play(dot.shift, 2 * UP) self.wait() self.play(dot.shift, 5 * DOWN) self.wait() self.play(dot.restore) self.wait()
[009]set_color/set_color_by_gradient set_color class ColorTest(Scene): def construct(self): self.set_color_test() # self.display_color_map() # self.gradient_test() def set_color_test(self): dot = Dot() rect = Rectangle() line = Line(ORIGIN, RIGHT) text = Text("Hello") group = VGroup(dot,rect,line, text).arrange(DOWN) #default color self.add(group) self.wait() #change color to red group.set_color(RED) self.play(ShowCreation(group)) ..
[008]align_to/arrange/arrange_in_grid align_to class AlignToTest(Scene): def construct(self): dir_str = [ 'UP', 'DOWN', 'LEFT', 'RIGHT'] dir_list = [ UP, DOWN, LEFT, RIGHT] rect = Rectangle(width=1, height=0.4) rect_tgt = Rectangle(width=3, height=2).shift(RIGHT * 3, UP * 2) self.add(rect, rect_tgt) for str, dir in zip(dir_str, dir_list): new_rect = rect.copy() obj = self.get_text_rect(str, new_rect) self.play(obj.align_to, rect_tgt..
[007]mob.get_left/mob.get_right rect = Rectangle(width=1.5, height=1) you_label = TextMobject("you") you_label.next_to(rect, RIGHT, MED_LARGE_BUFF) arrow = Arrow(you_label.get_left(), rect.get_right() + 0.5 * LEFT, buff=0.1) self.add(rect,you_label, arrow) self.wait()
[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}..