반응형
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, dir)
self.wait()
def get_text_rect(self, str, rect):
text = Text(str, font='Arial', stroke_width=0.1, size=0.2)
text.move_to(rect)
return VGroup(rect,text)
arrange (1)
class ArrangeTest(Scene):
def construct(self):
str = ['Hello', 'This', 'is', 'Arrange', 'Test']
self.display_text1(str)
# self.display_text2(str)
def display_text1(self, str):
text = VGroup()
for s in str:
t = self.get_text(s)
text.add(t)
text.to_edge(UP, buff=1)
text.arrange(DOWN, buff=0.5)
self.play(Write(text), run_time=3)
self.wait()
self.remove(text)
text.move_to(ORIGIN).to_edge(LEFT, buff=1)
text.arrange(RIGHT, buff=0.2)
def get_text(self,str):
return Text(str, font='굴림', stroke_width=0, size=0.5)
self.play(Write(text), run_time=3)
self.wait()
self.remove(text)
arrange (2)
class ArrangeTest(Scene):
def construct(self):
str = ['Hello', 'This', 'is', 'Arrange', 'Test']
# self.display_text1(str)
self.display_text2(str)
def display_text2(self, str):
text = VGroup(*[self.get_text(s) for s in str ])
text.move_to(ORIGIN).to_edge(UP, buff=1)
text.arrange(DOWN, center=False, aligned_edge = LEFT, buff=0.5)
self.play(Write(text), run_time=3)
self.wait()
self.remove(text)
text.move_to(ORIGIN).to_edge(LEFT, buff=1)
text.arrange(LEFT, buff=0.2)
# text.arrange(RIGHT, buff=0.2)
self.play(Write(text), run_time=3)
self.wait()
def get_text(self,str):
return Text(str, font='굴림', stroke_width=0, size=0.5)
arrange_in_grid
class ArrangeInGridTest(Scene):
def construct(self):
y = 20
x = 30
colors = [RED, GREEN, BLUE]
dots = VGroup(*[Dot() for x in range(y * x)])
dots.arrange_in_grid(y, x, buff=SMALL_BUFF)
for i in range(0, y*x):
dots[i].set_color(colors[i % 3])
self.add(dots)
self.wait()
반응형
'Programming > Manim code' 카테고리의 다른 글
[011]Text/TextMobject (0) | 2020.05.05 |
---|---|
[010]save_state/restore (0) | 2020.05.05 |
[007]mob.get_left/mob.get_right (0) | 2020.05.05 |
[006]Example: Coordinate Methods (0) | 2020.05.05 |
[005]mob.shift (0) | 2020.05.05 |