본문 바로가기

Programming/Manim code

[38]Animation: Creation

반응형

Showing

    def showing(self):
        text = Text("Hello. This is animation test", size=0.5, stroke_width=0)
        circle1 = Circle(radius=1)
        circle2 = Circle(radius=1, fill_color=YELLOW, fill_opacity=1)
        line = Line(LEFT,RIGHT, stroke_width=10).set_width(4)

        circles = VGroup(circle1, circle2)

        text.next_to(circles,UP)
        circles.arrange(RIGHT)
        line.next_to(circles,DOWN)

        mobs = VGroup(text,circles,line)

        ani_classes = {
            "ShowCreation": ShowCreation,
            "Write": Write,
            "DrawBorderThenFill": DrawBorderThenFill,
            "ShowIncreasingSubsets": ShowIncreasingSubsets,
            "ShowSubmobjectsOneByOne": ShowSubmobjectsOneByOne,
            "Uncreate": Uncreate,
        }

        idx=1
        for name, ani in ani_classes.items():
            self.do_ani(idx, name, ani, mobs)
            idx += 1

    def do_ani(self, idx, ani_name, ani_class, mobs):
        text = Text(str(idx)+". "+ani_name, stroke_width=0, size=0.4, color=YELLOW)
        text.to_corner(UL)

        self.add(text)
        self.wait()
        self.play(ani_class(mobs), run_time=4)
        self.wait()
        self.remove(text,mobs)

 

 

 


Fading

    def fading(self):
        ani_classes = {
            "FadeIn": (FadeIn,),
            "FadeInFrom": (FadeInFrom, LEFT),
            "FadeInFromDown": (FadeInFromDown, ),
            "FadeInFromLarge": (FadeInFromLarge, ),
            "FadeInFromPoint": (FadeInFromPoint, DL),
            "FadeOut": (FadeOut, ),
            "FadeOutAndShift": (FadeOutAndShift, UP),
            "FadeOutAndShiftDown": (FadeOutAndShiftDown, ),
            "ShrinkToCenter": (ShrinkToCenter,),
            "VFadeIn": (VFadeIn,),
            "VFadeOut": (VFadeOut,),
        }

        idx = 1
        for name, ani in ani_classes.items():
            self.do_ani(idx,name, ani)
            idx += 1

    def do_ani(self, idx, ani_name, ani):
        def get_obj():
            text = Text("Hello. This is animation test", size=0.5, stroke_width=0)
            circle1 = Circle(radius=1)
            circle2 = Circle(radius=1, fill_color=YELLOW, fill_opacity=1)
            line = Line(LEFT, RIGHT, stroke_width=10).set_width(4)

            circles = VGroup(circle1, circle2)

            text.next_to(circles, UP)
            circles.arrange(RIGHT)
            line.next_to(circles, DOWN)

            return VGroup(text, circles, line)

        mobs = get_obj()
        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()

        if len(ani) == 1:
            self.play(ani[0](mobs), run_time=4)
        else:
            self.play(ani[0](mobs, ani[1:]), run_time=4)

        self.wait()
        self.remove(name_text, mobs)    

 

 

 


 

growing

    def do_ani(self, idx, ani_name, ani, obj=None):
        def get_obj():
            text = Text("Hello. This is animation test", size=0.5, stroke_width=0)
            circle1 = Circle(radius=1)
            circle2 = Circle(radius=1, fill_color=YELLOW, fill_opacity=1)
            line = Line(LEFT, RIGHT, stroke_width=10).set_width(4)

            circles = VGroup(circle1, circle2)

            text.next_to(circles, UP)
            circles = VGroup(circle1, circle2)
            circles.arrange(RIGHT)
            line.next_to(circles, DOWN)

            return VGroup(text, circles, line)

        if obj is None:
            mobs = get_obj()
        else:
            mobs = obj

        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()

        if len(ani) == 1:
            self.play(ani[0](mobs), run_time=4)
        elif len(ani)==2:
            self.play(ani[0](mobs, ani[1]), run_time=4)
        elif len(ani) == 3:
            self.play(ani[0](mobs, ani[1], ani[2]), run_time=4)
        else:
            self.play(ani[0](mobs, ani[1:]), run_time=4)

        self.wait()
        self.remove(name_text, mobs)

    def growing(self):
        ani_classes = {
            "GrowFromPoint": (GrowFromPoint, DR),
            "GrowFromCenter": (GrowFromCenter, ),
            "GrowFromEdge": (GrowFromEdge, DL),
            "SpinInFromNothing": (SpinInFromNothing, ),
        }

        grow_arrow_class = {"GrowArrow": (GrowArrow,),}

        idx = 1
        for name, ani in ani_classes.items():
            self.do_ani(idx,name, ani)
            idx += 1

        arrow = Arrow(LEFT,RIGHT, color=YELLOW, buff=0)
        self.do_ani(idx,"GrowArrow",grow_arrow_class["GrowArrow"],obj=arrow)

 

 

 

반응형

'Programming > Manim code' 카테고리의 다른 글

[40]Moving/Rotating  (0) 2020.05.12
[39]Indicating  (0) 2020.05.12
[37]Animation's rate_func  (0) 2020.05.12
[34]GraphScene  (0) 2020.05.12
[33]NumberPlane  (0) 2020.05.12