LoginSignup
1
1

More than 3 years have passed since last update.

manimの作法 その26

Posted at

概要

manimの作法、調べてみた。
ImageMobject使ってみた。

サンプルコード

from manimlib.imports import *

def shift_up(mobject):
    return mobject.shift(2 * UP)

class test(Scene):
    def construct(self):
        square = ImageMobject('res10.png')
        anno = TextMobject("Show Creation")
        anno.shift(2 * DOWN)
        self.add(anno)
        self.play(ShowCreation(square))
        self.remove(square)
        self.remove(anno)

        square = ImageMobject('res10.png')
        anno = TextMobject("Uncreate")
        anno.shift(2 * DOWN)
        self.add(anno)
        self.add(square)
        self.play(Uncreate(square))
        self.remove(square)
        self.remove(anno)

        square = ImageMobject('res10.png')
        circle = ImageMobject('res12.png')
        anno = TextMobject("Transform")
        anno.shift(2 * DOWN)
        self.add(anno)
        self.add(square)
        self.play(Transform(square, circle))
        square.generate_target()
        square.target.move_to(2 * UP)
        self.play(MoveToTarget(square))
        self.remove(square)
        self.remove(circle)
        self.remove(anno)

        square = ImageMobject('res10.png')
        circle = ImageMobject('res12.png')
        anno = TextMobject("Replacement Transform")
        anno.shift(2 * DOWN)
        self.add(anno)
        self.add(square)
        self.play(ReplacementTransform(square, circle))
        circle.generate_target()
        circle.target.move_to(2 * UP)
        self.play(MoveToTarget(circle))
        self.remove(square)
        self.remove(circle)
        self.remove(anno)

        square = ImageMobject('res10.png')
        circle = ImageMobject('res12.png')
        anno = TextMobject("Transform from copy")
        anno.shift(2 * DOWN)
        self.add(anno)
        self.add(square)
        self.play(TransformFromCopy(square, circle))
        self.remove(circle)
        self.wait(2)
        self.remove(square)
        self.remove(circle)
        self.remove(anno)

        square = ImageMobject('res10.png')
        circle = ImageMobject('res12.png')
        anno = TextMobject("Clockwise transform")
        anno.shift(2 * DOWN)
        self.add(anno)
        self.add(square)
        self.play(ClockwiseTransform(square, circle))
        self.remove(square)
        self.remove(circle)
        self.remove(anno)

        square = ImageMobject('res10.png')
        circle = ImageMobject('res12.png')
        anno = TextMobject("Counterclockwise transform")
        anno.shift(2 * DOWN)
        self.add(anno)
        self.add(square)
        self.play(CounterclockwiseTransform(square, circle))
        self.remove(square)
        self.remove(circle)
        self.remove(anno)

        square = ImageMobject('res10.png')
        square.generate_target()
        square.target.shift(2 * UP)
        anno = TextMobject("Move to target")
        anno.shift(2 * DOWN)
        self.add(square)
        self.play(MoveToTarget(square))
        self.remove(square)
        self.remove(anno)

        square = ImageMobject('res10.png')
        anno = TextMobject("Apply pointwise function")
        anno.shift(2 * DOWN)
        self.add(anno)
        self.add(square)
        self.play(ApplyPointwiseFunction(lambda x: 2 * x + UP, square))
        self.remove(square)
        self.remove(anno)

        square = ImageMobject('res10.png')
        anno = TextMobject("Scale in place")
        anno.shift(2 * DOWN)
        self.add(anno)
        self.add(square)
        self.play(ScaleInPlace(square, 0.5))
        self.remove(square)
        self.remove(anno)

        square = ImageMobject('res10.png')
        anno = TextMobject("Shrink to center")
        anno.shift(2 * DOWN)
        self.add(anno)
        self.add(square)
        self.play(ShrinkToCenter(square))
        self.remove(square)
        self.remove(anno)

        square = ImageMobject('res10.png')
        anno = TextMobject("Restore")
        anno.shift(2 * DOWN)
        self.add(anno)
        square.save_state()
        circle = ImageMobject('res12.png')
        self.play(Transform(square, circle))
        square.generate_target()
        square.target.shift(2 * UP)
        self.play(MoveToTarget(square))
        self.play(Restore(square))
        self.remove(square)
        self.remove(circle)
        self.remove(anno)

        square = ImageMobject('res10.png')
        anno = TextMobject("Apply Function")
        anno.shift(2 * DOWN)
        self.add(anno)
        self.add(square)
        self.play(ApplyFunction(shift_up, square))
        self.remove(square)
        self.remove(anno)

        mat = [[1.0, 0.5], [1.0, 0.0]]
        square = ImageMobject('res10.png')
        anno = TextMobject("Apply Matrix")
        anno.shift(2 * DOWN)
        self.add(anno)
        self.add(square)
        self.play(ApplyMatrix(mat, square))
        self.remove(square)
        self.remove(anno)

        square = ImageMobject('res10.png')
        anno = TextMobject("Apply Complex Function")
        anno.shift(2 * DOWN)
        self.add(anno)
        self.add(square)
        self.play(ApplyComplexFunction(lambda complex_num: complex_num + 2 * np.complex(0, 1), square))
        self.remove(square)
        self.remove(anno)

        square = ImageMobject('res10.png')
        circle = Circle()
        circle.shift(2 * UP + 2 * RIGHT)
        triangle = Triangle()
        triangle.shift(2 * UP + 2 * LEFT)
        anno = TextMobject("Cyclic Replace")
        anno.shift(2 * DOWN)
        self.add(anno)
        self.add(square)
        self.add(circle)
        self.add(triangle)
        self.play(CyclicReplace(square, circle, triangle))
        self.remove(square)
        self.remove(circle)
        self.remove(triangle)
        self.remove(anno)

        square = ImageMobject('res10.png')
        anno = TextMobject("Fade In")
        anno.shift(2 * DOWN)
        self.add(anno)
        self.play(FadeIn(square))
        self.remove(square)
        self.remove(anno)

        square = ImageMobject('res10.png')
        anno = TextMobject("Fade Out")
        anno.shift(2 * DOWN)
        self.add(anno)
        self.add(square)
        self.play(FadeOut(square))
        self.remove(square)
        self.remove(anno)

        square = ImageMobject('res10.png')
        for label, edge in zip(["LEFT", "RIGHT", "UP", "DOWN"], [LEFT, RIGHT, UP, DOWN]):
            anno = TextMobject(f"Fade In from {label}")
            anno.shift(2 * DOWN)
            self.add(anno)
            self.play(FadeInFrom(square, edge))
            self.remove(anno, square)

        square = ImageMobject('res10.png')
        for label, edge in zip(["LEFT", "RIGHT", "UP", "DOWN"], [LEFT, RIGHT, UP, DOWN]):
            anno = TextMobject(f"Fade Out and shift {label}")
            anno.shift(2 * DOWN)
            self.add(anno)
            self.play(FadeOutAndShift(square, edge))
            self.remove(anno, square)

        square = ImageMobject('res10.png')
        for factor in [0.1, 0.5, 0.8, 1, 2, 5]:
            anno = TextMobject(f"Fade In from large scale\_factor={factor}")
            anno.shift(2 * DOWN)
            self.add(anno)
            self.play(FadeInFromLarge(square, scale_factor = factor))
            self.remove(anno, square)

        square = ImageMobject('res10.png')
        for i in range(-6, 7, 2):
            anno = TextMobject(f"Fade In from point {i}")
            anno.shift(2 * DOWN)
            self.add(anno)
            self.play(FadeInFromPoint(square, point = i))
            self.remove(anno, square)

        for label, edge in zip(["LEFT", "RIGHT", "UP", "DOWN"], [LEFT, RIGHT, UP, DOWN]):
            anno = TextMobject(f"Grow from {label} edge")
            anno.shift(2 * DOWN)
            self.add(anno)
            square = ImageMobject('res10.png')
            self.play(GrowFromEdge(square, edge))
            self.remove(anno, square)

        square = ImageMobject('res10.png')
        anno = TextMobject("Grow from center")
        anno.shift(2 * DOWN)
        self.add(anno)
        self.play(GrowFromCenter(square))
        self.remove(square)
        self.remove(anno)

        square = ImageMobject('res10.png')
        for diag in [UP + LEFT, UP + RIGHT, DOWN + LEFT, DOWN + RIGHT]:
            self.play(FadeInFrom(square, diag))
        self.remove(square)




生成した動画

以上。

1
1
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
1