LoginSignup
1
0

More than 3 years have passed since last update.

manimの作法 その28

Posted at

概要

manimの作法、調べてみた。
animation、全部使ってみた2。

サンプルコード

from manimlib.imports import *

class test(Scene):
    def construct(self):
        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Text0").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        self.play(*[ShowCreation(mob) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Text1").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        self.add(mobjects)
        self.wait(0.3)
        self.play(*[Uncreate(mob) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        vmobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Text2").scale(2))
        vmobjects.scale(1.5)
        vmobjects.arrange_submobjects(RIGHT, buff = 2)
        self.play(*[DrawBorderThenFill(mob) for mob in vmobjects])
        self.wait()
        self.play(FadeOut(vmobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Text3").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        self.play(*[Write(mob) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Text4").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        self.add(mobjects)
        self.wait(0.3)
        self.play(*[FadeOut(mob) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Text5").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        self.play(*[FadeIn(mob) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Text6").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        directions = [UP, LEFT, DOWN, RIGHT]
        for direction in directions:
            self.play(*[FadeInFrom(mob,direction) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Text7").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        self.play(*[FadeInFromDown(mob) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Text8").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        directions = [UP, LEFT, DOWN, RIGHT]
        self.add(mobjects)
        self.wait(0.3)
        for direction in directions:
            self.play(*[FadeOutAndShift(mob,direction) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Text9").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        self.play(*[FadeOutAndShiftDown(mob) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Texta").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        scale_factors = [0.3, 0.8, 1, 1.3, 1.8]
        for scale_factor in scale_factors:
            t_scale_factor = TextMobject(f"\\tt scale\\_factor = {scale_factor}")
            t_scale_factor.to_edge(UP)
            self.add(t_scale_factor)
            self.play(*[FadeInFromLarge(mob, scale_factor) for mob in mobjects])
            self.remove(t_scale_factor)
        self.wait(0.3)
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Textb").scale(2))
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        directions = [UP, LEFT, DOWN, RIGHT]
        for direction in directions:
            self.play(*[GrowFromPoint(mob, mob.get_center() + direction * 3) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Textc").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        self.play(*[GrowFromCenter(mob) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Textd").scale(2))
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        directions = [UP, LEFT, DOWN, RIGHT]
        for direction in directions:
            self.play(*[GrowFromEdge(mob, direction) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Arrow(LEFT, RIGHT), Vector(RIGHT * 2))
        mobjects.scale(3)
        mobjects.arrange_submobjects(DOWN, buff = 2)
        self.play(*[GrowArrow(mob) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Square(), RegularPolygon(fill_opacity = 1), TextMobject("Texte").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        self.play(*[SpinInFromNothing(mob) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Square(), RegularPolygon(fill_opacity = 1), TextMobject("Textf").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        self.play(*[ShrinkToCenter(mob) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Dot(), TexMobject("x"))
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        mobject_or_coord = [*mobjects, mobjects.get_right() + RIGHT * 2]
        colors = [GRAY, RED, BLUE]
        self.add(mobjects)
        for obj,color in zip(mobject_or_coord, colors):
            self.play(FocusOn(obj, color = color))
        self.wait()
        self.play(FadeOut(mobjects))

        formula = TexMobject("f(", "x", ")")
        dot = Dot()
        VGroup(formula, dot).scale(3).arrange_submobjects(DOWN, buff = 3)
        self.add(formula, dot)
        for mob in [formula[1], dot]:
            self.play(Indicate(mob))
        self.wait()
        self.remove(formula)
        self.remove(dot)

        mobjects = VGroup(Dot(), TexMobject("x0")).scale(2)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        mobject_or_coord = [*mobjects, mobjects.get_right() + RIGHT * 2]
        colors = [GRAY, RED, BLUE]
        self.add(mobjects)
        for obj,color in zip(mobject_or_coord,colors):
            self.play(Flash(obj, color = color, flash_radius = 0.5))
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Dot(), TexMobject("x1")).scale(2)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        self.add(mobjects)
        self.wait(0.2)
        for obj in mobjects:
            self.play(CircleIndicate(obj))
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Textg").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        self.play(*[ShowCreationThenDestruction(mob) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Texth").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        self.play(*[ShowCreationThenFadeOut(mob) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Texti").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        self.add(mobjects)
        self.play(*[ShowPassingFlashAround(mob) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Textj").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        self.add(mobjects)
        self.play(*[ShowCreationThenDestructionAround(mob) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Textk").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        self.add(mobjects)
        self.play(*[ShowCreationThenFadeAround(mob) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Textl").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        self.add(mobjects)
        self.play(*[ApplyWave(mob) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Textm").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        self.add(mobjects)
        self.play(*[WiggleOutThenIn(mob) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobjects = VGroup(Circle(), Circle(fill_opacity = 1), TextMobject("Textn").scale(2))
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT, buff = 2)
        self.add(mobjects)
        self.play(*[TurnInsideOut(mob) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        mobject = RegularPolygon(3).scale(2)
        self.add(mobject)
        for n in range(4, 9):
            self.play(Transform(mobject, RegularPolygon(n).scale(2)))
        self.wait(0.3)
        self.play(FadeOut(mobject))

        polygons = [*[RegularPolygon(n).scale(2) for n in range(3, 9)]]
        self.add(polygons[0])
        for i in range(len(polygons) - 1):
            self.play(ReplacementTransform(polygons[i], polygons[i + 1]))
        self.wait(0.3)
        self.remove(polygons[0])
        self.remove(polygons[1])
        self.remove(polygons[2])
        self.remove(polygons[3])
        self.remove(polygons[4])
        self.remove(polygons[5])



        polygons = VGroup(*[RegularPolygon(n).scale(0.7) for n in range(3, 9)]).arrange_submobjects(RIGHT, buff = 1)
        self.add(polygons[0])
        for i in range(len(polygons) - 1):
            self.play(ClockwiseTransform(polygons[0], polygons[i + 1]))
        self.wait(0.3)
        self.play(FadeOut(polygons))

        polygons = VGroup(*[RegularPolygon(n).scale(0.7) for n in range(3, 9)]).arrange_submobjects(RIGHT, buff = 1)
        self.add(polygons[0])
        for i in range(len(polygons) - 1):
            self.play(CounterclockwiseTransform(polygons[0], polygons[i + 1]))
        self.wait(0.3)
        self.play(FadeOut(polygons))

        mobject = Square()
        mobject.generate_target()
        VGroup(mobject, mobject.target).arrange_submobjects(RIGHT, buff = 3)
        mobject.target.rotate(PI / 4).scale(2).set_stroke(PURPLE, 9).set_fill(ORANGE, 1)
        self.add(mobject)
        self.wait(0.3)
        self.play(MoveToTarget(mobject))
        self.wait(0.3)
        self.play(FadeOut(mobject))

        dot = Dot()
        text = TextMobject("Texto")
        dot.next_to(text, LEFT)
        self.add(text, dot)
        self.play(ApplyMethod(text.scale, 3, {
            "about_point": dot.get_center()
        }))
        self.wait(0.3)
        self.remove(dot)
        self.remove(text)

        text = TextMobject("Textp")
        self.add(text)
        def spread_out(p):
            p = p + 2 * DOWN
            return (FRAME_X_RADIUS + FRAME_Y_RADIUS) * p / get_norm(p)
        self.play(ApplyPointwiseFunction(spread_out, text))
        text = TextMobject("Text").set_width(FRAME_WIDTH)
        colors = [RED, PURPLE, GOLD, TEAL]
        self.add(text)
        for color in colors:
            self.play(FadeToColor(text, color))
        self.wait(0.3)
        self.remove(text)

        text = TextMobject("Textq").set_width(FRAME_WIDTH / 2)
        scale_factors = [2, 0.3, 0.6, 2]
        self.add(text)
        for scale_factor in scale_factors:
            self.play(ScaleInPlace(text, scale_factor))
        self.wait(0.3)
        self.remove(text)

        text = TextMobject("Original").set_width(FRAME_WIDTH / 2)
        text.save_state()
        text_2 = TextMobject("Modified").set_width(FRAME_WIDTH / 1.5).set_color(ORANGE).to_corner(DL)
        self.add(text)
        self.play(Transform(text, text_2))
        self.play(text.shift, RIGHT, text.rotate, PI / 4)
        self.play(Restore(text))
        self.wait(0.7)
        self.remove(text)
        self.remove(text_2)

        text = TextMobject("Texts").to_corner(DL)
        self.add(text)
        def apply_function(mob):
            mob.scale(2)
            mob.to_corner(UR)
            mob.rotate(PI / 4)
            mob.set_color(RED)
            return mob
        self.play(ApplyFunction(apply_function, text))
        self.wait(0.3)
        self.remove(text)

        def plane_wave_homotopy(x, y, z, t):
            norm = get_norm([x, y])
            tau = interpolate(5, -5, t) + norm / FRAME_X_RADIUS
            alpha = sigmoid(tau)
            return [x, y + 0.5 * np.sin(2 * np.pi * alpha) - t * SMALL_BUFF / 2, z]
        mobjects = VGroup(TextMobject("Text").scale(3), Square(), ).arrange_submobjects(RIGHT, buff = 2)
        self.add(mobjects)
        self.play(*[Homotopy(plane_wave_homotopy, mob) for mob in mobjects])
        self.wait(0.3)
        self.play(FadeOut(mobjects))

        def func(t):
            return t * 0.5 * RIGHT
        mobjects = VGroup(TextMobject("Textt").scale(3), Square(), ).arrange_submobjects(RIGHT, buff = 2)
        self.play(*[PhaseFlow(func, mob, run_time = 2,) for mob in mobjects])
        self.wait()
        self.play(FadeOut(mobjects))

        line = Line(ORIGIN, RIGHT * FRAME_WIDTH, buff = 1)
        line.move_to(ORIGIN)
        dot = Dot()
        dot.move_to(line.get_start())
        self.add(line, dot)
        self.play(MoveAlongPath(dot, line))
        self.wait(0.3)
        self.remove(line)
        self.remove(dot)

        square = Square().scale(2)
        self.add(square)
        self.play(Rotating(square,radians = PI / 4, run_time = 2))
        self.wait(0.3)
        self.play(Rotating(square,radians = PI, run_time = 2, axis = RIGHT))
        self.wait(0.3)
        self.remove(square)

        square = Square().scale(2)
        self.add(square)
        self.play(Rotate(square, PI / 4, run_time = 2))
        self.wait(0.3)
        self.play(Rotate(square, PI, run_time = 2, axis = RIGHT))
        self.wait(0.3)
        self.remove(square)
        self.wait()

        mobject = RegularPolygon(3).scale(2)
        self.add(mobject)
        for n in range(4, 9):
            self.play(TransformFromCopy(mobject, RegularPolygon(n).scale(2)))
        self.wait(0.3)
        self.play(FadeOut(mobject))
        self.wait()





生成した動画

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0