반응형
class TransformTest(Scene):
def construct(self):
self.transform_to_target()
# self.cyclic()
def get_text(self, str):
return Text(str, size=0.5, color=YELLOW, stroke_width=0)
def transform_to_target(self):
self.left_name = self.get_text("A").shift(UP * 2 + LEFT * 3)
self.right_name = self.get_text("B").shift(UP * 2 + RIGHT * 3)
self.square = Square().shift(LEFT*3)
self.circle = Circle(fill_opacity=1, color=RED).shift(RIGHT*3)
self.objs = VGroup(self.left_name, self.right_name, self.square, self.circle)
self.objs.save_state()
t_classes = {
"1. Transform": Transform,
"2. ClockwiseTransform": ClockwiseTransform,
"3. CounterclockwiseTransform": CounterclockwiseTransform,
}
for name, cla in t_classes.items():
self.transform(name, cla)
self.replacement_transform("4. ReplacementTransform", ReplacementTransform)
self.transform_from_copy("5. TransformFromCopy", TransformFromCopy)
self.do_swap("6. Swap", Swap)
def transform(self, name, ani_class):
ani_name = self.get_text(name).to_corner(UL)
self.add(ani_name, self.objs)
self.wait()
self.play(
ani_class(self.square, self.circle, run_time=3),
FadeOut(self.right_name),
self.left_name.move_to, self.right_name, run_time=3,
)
self.wait()
self.remove(ani_name, self.objs)
self.objs.restore()
def replacement_transform(self, name, ani_class):
ani_name = self.get_text(name).to_corner(UL)
self.add(ani_name, self.objs)
self.play(
ani_class(self.square, self.circle, run_time=2),
FadeOut(self.left_name),
)
self.wait()
self.remove(ani_name, self.objs)
self.objs.restore()
def transform_from_copy(self, name, ani_class):
ani_name = self.get_text(name).to_corner(UL)
self.add(ani_name, self.objs)
self.play(
ani_class(self.square, self.circle, run_time=2),
)
self.wait()
self.remove(ani_name, self.objs)
self.objs.restore()
def do_swap(self, name, ani_class):
ani_name = self.get_text(name).to_corner(UL)
self.add(ani_name, self.objs)
self.play(
ani_class(self.square, self.circle, run_time=2),
self.left_name.shift, RIGHT*6,
self.right_name.shift, LEFT * 6,
)
self.wait()
self.remove(ani_name, self.objs)
self.objs.restore()
Transform, ReplaceTransform, TransformFromCopy
class DifferenceOfTransform(Scene):
def construct(self):
self.tri = Triangle().to_edge(LEFT, buff=0.5)
self.square = Square()
self.circle = Circle().to_edge(RIGHT, buff=0.5)
self.group = VGroup(self.tri, self.square, self.circle)
self.group.save_state()
self.transform("Transform(A,B)", "Transform(A,C)")
self.replacement_transform("ReplacementTransform(A,B)", "ReplacementTransform(B,C)")
self.transform_from_copy("TransformFromCopy(A,B)", "TransformFromCopy(B,C)")
def transform(self, s1, s2):
text = VGroup(
Text(s1, stroke_width=0, color=YELLOW, size=0.4),
Text(s2, stroke_width=0, color=YELLOW, size=0.4),
).arrange(DOWN, aligned_edge=LEFT)
self.add(text.to_edge(UP, buff=1))
self.group.restore()
self.add(self.tri)
self.play(Transform(self.tri, self.square), run_time=3)
self.play(Transform(self.tri, self.circle), run_time=3)
self.wait()
self.remove(text, self.tri, self.square, self.circle)
def replacement_transform(self, s1, s2):
text = VGroup(
Text(s1, stroke_width=0, color=YELLOW, size=0.4),
Text(s2, stroke_width=0, color=YELLOW, size=0.4),
).arrange(DOWN, aligned_edge=LEFT)
self.add(text.to_edge(UP, buff=1))
self.group.restore()
self.play(ReplacementTransform(self.tri, self.square), run_time=3)
self.play(ReplacementTransform(self.square, self.circle), run_time=3)
self.wait()
self.remove(text, self.tri, self.square, self.circle)
def transform_from_copy(self, s1, s2):
text = VGroup(
Text(s1, stroke_width=0, color=YELLOW, size=0.4),
Text(s2, stroke_width=0, color=YELLOW, size=0.4),
).arrange(DOWN, aligned_edge=LEFT)
self.add(text.to_edge(UP, buff=1))
self.group.restore()
self.add(self.tri)
self.play(TransformFromCopy(self.tri, self.square), run_time=3)
self.play(TransformFromCopy(self.square, self.circle), run_time=3)
self.wait()
반응형
'Programming > Manim code' 카테고리의 다른 글
[43]Transform(3) (0) | 2020.05.20 |
---|---|
[42]Transform (2) (0) | 2020.05.12 |
[40]Moving/Rotating (0) | 2020.05.12 |
[39]Indicating (0) | 2020.05.12 |
[38]Animation: Creation (0) | 2020.05.12 |