반응형
class IndicatingTest(Scene):
def construct(self):
self.indicating()
def indicating(self):
ani_classes = {
"ShowCreationThenDestruction": (ShowCreationThenDestruction,),
"Indicate": (Indicate, ),
"WiggleOutThenIn": (WiggleOutThenIn,),
"ApplyWave": (ApplyWave, ),
}
ani_classes_need_pre_exist={
"CircleIndicate": (CircleIndicate,),
"FocusOn": (FocusOn,),
"Flash": (Flash,),
"ShowPassingFlashAround": (ShowPassingFlashAround,),
"ShowCreationThenDestructionAround": (ShowCreationThenDestructionAround,),
"ShowCreationThenFadeAround": (ShowCreationThenFadeAround,),
"ShowPassingFlash": (ShowPassingFlash,),
"AnimationOnSurroundingRectangle": (AnimationOnSurroundingRectangle,),
}
idx = 1
for name, ani in ani_classes.items():
self.do_ani(idx, name, ani)
idx += 1
#need to existing mobject prior to play animation
for name, ani in ani_classes_need_pre_exist.items():
self.do_ani(idx, name, ani, need_prior=True)
idx += 1
def do_ani(self, idx, ani_name, ani, obj=None, need_prior=False):
def get_obj():
text = TextMobject("Hello. This is animation test")
circle1 = Circle(radius=1)
circle2 = Circle(radius=1, fill_color=YELLOW, fill_opacity=1)
circles = VGroup(circle1, circle2)
dot = Dot()
arrow = Arrow(LEFT, RIGHT, stroke_width=5).set_width(3)
dot.next_to(arrow, LEFT, buff=0.5)
dot_arrow = VGroup(dot, arrow)
text.next_to(circles, UP)
circles = VGroup(circle1, circle2)
circles.arrange(RIGHT)
dot_arrow.next_to(circles, DOWN)
return VGroup(text, circle1, circle2, dot, arrow)
if obj is None:
mobs = get_obj()
else:
mobs = obj
if need_prior:
self.add(mobs)
name_text = Text(str(idx) + ". " + ani_name, stroke_width=0, size=0.4, color=YELLOW)
name_text.to_corner(UL)
self.add(name_text)
self.wait()
for mob in mobs:
if len(ani) == 1:
self.play(ani[0](mob), run_time=1)
elif len(ani) == 2:
self.play(ani[0](mob, ani[1]), run_time=1)
elif len(ani) == 3:
self.play(ani[0](mob, ani[1], ani[2]), run_time=1)
else:
self.play(ani[0](mob, ani[1:]), run_time=1)
self.wait()
self.remove(name_text, mobs)
반응형
'Programming > Manim code' 카테고리의 다른 글
[41]Transform(1) (0) | 2020.05.12 |
---|---|
[40]Moving/Rotating (0) | 2020.05.12 |
[38]Animation: Creation (0) | 2020.05.12 |
[37]Animation's rate_func (0) | 2020.05.12 |
[34]GraphScene (0) | 2020.05.12 |