Manim-Examples-Docker

claude

この記事では、Dockerを使用してManimでアニメーションを作成するための例と手順について説明します。


こちらの記事もおすすめ

【GoogleColabノートブック付】claude3を使用してスライドムービー作ってみた
こちらの記事もおすすめ内容の要約プロンプト下記リポジトリを初心者でも分かるように解説して出力このリポジトリは「Petals」というプロジェクトのソースコードが含まれています。Petalsは、大規模な言語モデル(LLM)を複数のコンピュータで...
Doubleが開発したClaude 3 AIコーディングアシスタントが革新的!無料でVS Codeに導入可能
はじめにプログラマーの皆さん、コーディングを加速させるツールをお探しではありませんか?そんなあなたに朗報です。革新的なAIコーディングアシスタント「Double」が登場しました。なんと、無料でVS Codeに導入することができるのです!Do...

Manimとは

Manim Community Edition
Animating technical concepts is traditionally pretty tedious since it can be difficult to make the animations precise enough to convey them accurately. Manim re...
  1. Pythonベース
    Pythonの知識があれば比較的簡単にアニメーションを作成できます。Pythonは初心者にも学びやすい言語なので、Manimを使い始めるハードルが低いのが良い点です。

  2. 豊富な数学オブジェクト
    数式、グラフ、ベクトル、行列など様々な数学オブジェクトをサポートしています。LaTeXを使って数式を綺麗に表示できるのも魅力的です。

  3. 柔軟なアニメーション
    オブジェクトの移動、変形、出現/消失など、様々なアニメーション効果を適用できます。カメラワークも自在にコントロール可能です。

  4. 高品質な出力
    レンダリング品質が高く、滑らかで見栄えのする動画を生成できます。解像度やフレームレートなども細かく設定できます。

  5. コミュニティの活発さ
    GitHubで公開されており、開発が活発に行われています。ドキュメントやサンプルコードも豊富で、コミュニティから情報を得やすいのも利点です。

初心者にとってはPythonの文法に慣れる必要がありますが、数学の面白さを伝えるための強力なツールであることは間違いありません。少しずつ使い方を学んでいけば、様々な数学コンテンツ作りに活用できるでしょう。数学や教育に興味がある人にはおすすめのライブラリだと思います。

セットアップ

まず、Manimの例を実行するためのDockerコンテナを設定するには、次のコマンドをターミナルで実行してください。

docker-compose up -d

このコマンドは、Dockerコンテナをビルドしてデタッチドモードで起動します。

デモと使用方法

以下に、異なるデモとそれらを実行するためのコマンドを示します。各デモは、特定のアニメーション効果を示しています。

Demo01: 四角から円へ


from manim import *

class SquareToCircle(Scene):
    def construct(self):
        circle = Circle()  # create a circle
        circle.set_fill(PINK, opacity=0.5)  # set color and transparency

        square = Square()  # create a square
        square.rotate(PI / 4)  # rotate a certain amount

        self.play(Create(square))  # animate the creation of the square
        self.play(Transform(square, circle))  # interpolate the square into the circle
        self.play(FadeOut(square))  # fade out animation
docker-compose exec manim manim -qm demo01_square_to_circle.py SquareToCircle

Demo02: テキストの表示


from manim import *

class displayText(Scene):
    def construct(self):
        # Create Text objects
        first_line = Text('Create cool animations')
        second_line = Text('using Manim')
        third_line = Text('Try it out yourself.', color=RED)

        # Position second line underneath first line
        second_line.next_to(first_line, DOWN)

        # Displaying text
        self.wait(1)
        self.play(Write(first_line), Write(second_line))
        self.wait(1)
        self.play(ReplacementTransform(first_line, third_line), FadeOut(second_line))
        self.wait(2)
docker-compose exec manim manim -qm demo02_displayText.py displayText

Demo03: 方程式の表示


from manim import *

class displayEquations(Scene):
    def construct(self):
        # Create Tex objects
        first_line = Text('Manim also allows you')
        second_line = Text('to show beautiful math equations')
        equation = Tex('$d\\left(p, q\\right)=d\\left(q, p\\right)=\\sqrt{(q_1-p_1)^2+(q_2-p_2)^2+...+(q_n-p_n)^2}=\\sqrt{\\sum_{i=1}^n\\left(q_i-p_i\\right)^2}$')

        # Position second line underneath first line
        second_line.next_to(first_line, DOWN)

        # Displaying text and equation
        self.play(Write(first_line), Write(second_line))
        self.wait(1)
        self.play(ReplacementTransform(first_line, equation), FadeOut(second_line))
        self.wait(3)
docker-compose exec manim manim -qm demo03_displayEquations.py displayEquations

Demo04: グラフの作成


from manim import *

class CreateGraph(Scene):
    def construct(self):
        axes = Axes(
            x_range=[-3, 3],
            y_range=[-5, 5],
            axis_config={"color": BLUE},
        )

        # Create Graph using the new plot method
        graph = axes.plot(lambda x: x**2, color=WHITE)
        graph_label = axes.get_graph_label(graph, label='x^{2}')

        graph2 = axes.plot(lambda x: x**3, color=WHITE)
        graph_label2 = axes.get_graph_label(graph2, label='x^{3}')

        # Display graph
        self.play(Create(axes), Create(graph), Write(graph_label))
        self.wait(1)
        self.play(Transform(graph, graph2), Transform(graph_label, graph_label2))
        self.wait(1)
docker-compose exec manim manim -qm demo04_CreateGraph.py CreateGraph

Demo05: 四角と円


from manim import *

class SquareAndCircle(Scene):
    def construct(self):
        circle = Circle()  # create a circle
        circle.set_fill(PINK, opacity=0.5)  # set the color and transparency

        square = Square()  # create a square
        square.set_fill(BLUE, opacity=0.5)  # set the color and transparency

        square.next_to(circle, RIGHT, buff=0.5)  # set the position
        self.play(Create(circle), Create(square))  # show the shapes on screen
docker-compose exec manim manim -qm demo05_SquareAndCircle.py SquareAndCircle

Demo06: アニメーション化された四角から円へ


from manim import *

class AnimatedSquareToCircle(Scene):
    def construct(self):
        circle = Circle()  # create a circle
        square = Square()  # create a square

        self.play(Create(square))  # show the square on screen
        self.play(square.animate.rotate(PI / 4))  # rotate the square
        self.play(
            ReplacementTransform(square, circle)
        )  # transform the square into a circle
        self.play(
            circle.animate.set_fill(PINK, opacity=0.5)
        )  # color the circle on screen
docker-compose exec manim manim -qm demo06_AnimatedSquareToCircle.py AnimatedSquareToCircle

Demo07: 異なる回転


from manim import *

class DifferentRotations(Scene):
    def construct(self):
        left_square = Square(color=BLUE, fill_opacity=0.7).shift(2 * LEFT)
        right_square = Square(color=GREEN, fill_opacity=0.7).shift(2 * RIGHT)
        self.play(
            left_square.animate.rotate(PI), Rotate(right_square, angle=PI), run_time=2
        )
        self.wait()
docker-compose exec manim manim -qm demo07_DifferentRotations.py DifferentRotations 

Demo08: GIFとして出力


from manim import *

class OutputGif(Scene):
    def construct(self):
        left_square = Square(color=RED, fill_opacity=0.4).shift(3 * LEFT)
        right_square = Square(color=BLUE, fill_opacity=0.8).shift(1 * RIGHT)
        self.play(
            left_square.animate.rotate(PI), Rotate(right_square, angle=PI), run_time=4
        )

        left_square2 = Square(color=BLUE, fill_opacity=0.8).shift(1 * LEFT)
        right_square2 = Square(color=BLUE, fill_opacity=0.3).shift(7 * RIGHT)
        self.play(Transform(left_square, left_square2))  # interpolate the square into the circle
        self.play(Transform(right_square, right_square2))  # interpolate the square into the circle

        self.play(
            left_square.animate.rotate(PI), Rotate(right_square, angle=PI), run_time=4
        )
        self.wait()
docker-compose exec manim manim -qm demo08_OutputGif.py OutputGif  --format=gif

Demo09: 背景色の変更


from manim import *

config.background_color = WHITE
config["background_color"] = WHITE

class BackgroundColor(Scene):
    def construct(self):
        axes = Axes(
            x_range=[-4, 4],
            y_range=[-6, 6],
            axis_config={"color": BLUE},
        )

        # Create Graph using the new plot method
        graph = axes.plot(lambda x: x**1, color=RED)
        graph_label = axes.get_graph_label(graph, label='x^{1}')

        graph2 = axes.plot(lambda x: x**4, color=RED)
        graph_label2 = axes.get_graph_label(graph2, label='x^{4}')

        # Display graph
        self.play(Create(axes), Create(graph), Write(graph_label))
        self.wait(1)
        self.play(Transform(graph, graph2), Transform(graph_label, graph_label2))
        self.wait(1)
docker-compose exec manim manim -qm demo09_BackgroundColor.py BackgroundColor

Demo10: 日本語テキストの表示


from manim import *

config.background_color = WHITE
Mobject.set_default(color = BLACK)

Tex.set_default(tex_template=TexTemplate(
    tex_compiler = "lualatex", 
    # tex_compiler = "luatex" でも可
    output_format = ".pdf", 
    preamble = r"""
        \usepackage{amsmath}
        \usepackage{amssymb}
        \usepackage{luatexja}
        \usepackage[haranoaji]{luatexja-preset}
    """
))

class displayTextJP(Scene):
    def construct(self):
        # Create Text objects
        first_line = Tex('Manimを使用して')
        second_line = Text('クールなアニメーションを作成する')
        third_line = Text('自分で試してみてください', color=RED)

        # Position second line underneath first line
        second_line.next_to(first_line, DOWN)

        # Displaying text
        self.wait(1)
        self.play(Write(first_line), Write(second_line))
        self.wait(1)
        self.play(ReplacementTransform(first_line, third_line), FadeOut(second_line))
        self.wait(2)
docker-compose exec manim manim -qm demo10_displayTextJP.py displayTextJP

Demo11: 縦向きビデオ


from manim import *

config.background_color = WHITE
Mobject.set_default(color = BLACK)

Tex.set_default(tex_template=TexTemplate(
    tex_compiler = "lualatex", 
    # tex_compiler = "luatex" でも可
    output_format = ".pdf", 
    preamble = r"""
        \usepackage{amsmath}
        \usepackage{amssymb}
        \usepackage{luatexja}
        \usepackage[haranoaji]{luatexja-preset}
    """
))

class VerticalVideo(Scene):
    def construct(self):
        # Create Text objects
        first_line = Tex('Manimを使用して')
        second_line = Text('クールなアニメーションを作成する')
        third_line = Text('自分で試してみてください', color=RED)

        # Position second line underneath first line
        second_line.next_to(first_line, DOWN)

        # Displaying text
        self.wait(1)
        self.play(Write(first_line), Write(second_line))
        self.wait(1)
        self.play(ReplacementTransform(first_line, third_line), FadeOut(second_line))
        self.wait(2)
docker-compose exec manim manim  -r 720,1280  -qm demo11_VerticalVideo.py VerticalVideo

Demo12: スライド


from manim import *

Tex.set_default(tex_template=TexTemplate(
    tex_compiler = "lualatex", 
    # tex_compiler = "luatex" でも可
    output_format = ".pdf", 
    preamble = r"""
        \usepackage{amsmath}
        \usepackage{amssymb}
        \usepackage{luatexja}
        \usepackage[haranoaji]{luatexja-preset}
    """
))

class V3DSlides(Scene):
    def construct(self):
        # スライド1: タイトル
        title = Tex("V3D: ビデオ拡散モデルによる\\\\効果的な3D生成手法", font_size=72)
        # title.to_edge(UP)
        self.play(Write(title))
        self.wait(2)
        self.play(FadeOut(title))

        # スライド2: 概要
        overview_title = Tex("概要", font_size=48)
        overview_title.to_edge(UP)
        overview_points1 = BulletedList(
            "自動3D生成への注目が高まっている",
            "最近の手法は生成速度を大幅に向上させたが、\\\\モデル容量や3Dデータの限界により詳細度が低い",
            "ビデオ拡散モデルの進歩に着目し、事前学習済み\\\\モデルの世界シミュレーション能力を活用するV3Dを提案",
            "幾何学的整合性の事前情報を導入し、ビデオ拡散モデルを\\\\マルチビュー整合性のある3Dジェネレータへと拡張",
        )
        overview_points1.scale(0.7)
        overview_points1.arrange(DOWN, aligned_edge=LEFT)
        overview_points1.next_to(overview_title, DOWN)

        overview_points2 = BulletedList(
            "これにより、最先端のビデオ拡散モデルを単一画像から\\\\360度のオービットフレームを生成するように微調整可能に",
            "専用の再構成パイプラインにより、3分以内に\\\\高品質なメッシュや3Dガウシアンを生成可能",
            "シーンレベルのノベルビュー合成にも拡張可能で、\\\\疎な入力ビューでカメラパスを正確に制御",
        )
        overview_points2.scale(0.7)
        overview_points2.arrange(DOWN, aligned_edge=LEFT)
        overview_points2.next_to(overview_points1, DOWN)

        self.play(Write(overview_title))
        self.play(Create(overview_points1), run_time=3)
        self.wait(1)
        self.play(Create(overview_points2), run_time=2)
        self.wait(2)
        self.play(FadeOut(overview_title), FadeOut(overview_points1), FadeOut(overview_points2))

        # スライド3: 提案手法 - オブジェクト中心の3D生成
        object_title = Tex("提案手法 - オブジェクト中心の3D生成", font_size=48)
        object_title.to_edge(UP)
        object_points1 = BulletedList(
            "1. ビデオ拡散モデルを合成3Dオブジェクトの\\\\360度オービットビデオでファインチューニング",
            "   - 前面ビューを条件として使用",
            "2. 生成されたマルチビューから3D再構成するためのパイプラインを設計",
            "   - 知覚的損失を採用し不整合の詳細を解消",
        )
        object_points1.scale(0.6)
        object_points1.arrange(DOWN, aligned_edge=LEFT)
        object_points1.next_to(object_title, DOWN)

        object_points2 = BulletedList(
            "   - 3D表現としてガウシアンスプラッティングを採用",
            "   - スペースカービングによる初期化で再構成を高速化",
            "   - メッシュ抽出のためのパイプラインも提案",
            "     - SDFで表面を抽出し、生成ビューでテクスチャをリファイン",
        )
        object_points2.scale(0.6)
        object_points2.arrange(DOWN, aligned_edge=LEFT)
        object_points2.next_to(object_points1, DOWN)

        self.play(Write(object_title))
        self.play(Create(object_points1), run_time=3)
        self.wait(1)
        self.play(Create(object_points2), run_time=2)
        self.wait(2)
        self.play(FadeOut(object_title), FadeOut(object_points1), FadeOut(object_points2))

        # スライド4: 提案手法 - シーンレベルのノベルビュー合成
        scene_title = Tex("提案手法 - シーンレベルのノベルビュー合成", font_size=48)
        scene_title.to_edge(UP)
        scene_points = BulletedList(
            "1. PixelNeRFエンコーダを統合し、ビデオ拡散モデルに\\\\ロバストな3D信号を与える",
            "   - カメラパスを正確に制御し、マルチビュー入力に対応",
            "2. 補助損失と実世界のポーズ付きビデオでのファインチューニングにより拡張",
            "   - 疎なビュー入力から任意のカメラパスでノベルビューを生成可能に",
        )
        scene_points.scale(0.7)
        scene_points.arrange(DOWN, aligned_edge=LEFT)
        scene_points.next_to(scene_title, DOWN)
        self.play(Write(scene_title))
        self.play(Create(scene_points), run_time=3)
        self.wait(2)
        self.play(FadeOut(scene_title), FadeOut(scene_points))

        # スライド5: 実験結果
        results_title = Tex("実験結果", font_size=48)
        results_title.to_edge(UP)
        results_points = BulletedList(
            "定性的および定量的評価により、提案手法の優位性を実証",
            "  - 特に生成品質とマルチビューの整合性において優れた性能",
            "オブジェクト中心およびシーンレベルの両方の実験で最先端の性能を達成",
        )
        results_points.scale(0.7)
        results_points.arrange(DOWN, aligned_edge=LEFT)
        results_points.next_to(results_title, DOWN)
        self.play(Write(results_title))
        self.play(Create(results_points), run_time=2)
        self.wait(2)
        self.play(FadeOut(results_title), FadeOut(results_points))

        # スライド6: まとめ
        summary_title = Tex("まとめ", font_size=48)
        summary_title.to_edge(UP)
        summary_points1 = BulletedList(
            "ビデオ拡散モデルを活用した効果的な3D生成手法V3Dを提案",
            "3Dデータセットでファインチューニングすることで、\\\\ビデオ拡散モデルを3Dジェネレータへと拡張",
            "専用の再構成パイプラインにより、3分以内に高品質な3Dアセットを生成可能",
        )
        summary_points1.scale(0.7)
        summary_points1.arrange(DOWN, aligned_edge=LEFT)
        summary_points1.next_to(summary_title, DOWN)

        summary_points2 = BulletedList(
            "広範な実験により提案手法の有効性を実証し、\\\\3Dタスクにおけるビデオ拡散モデルのさらなる応用の可能性を示唆",
        )
        summary_points2.scale(0.7)
        summary_points2.arrange(DOWN, aligned_edge=LEFT)
        summary_points2.next_to(summary_points1, DOWN)

        self.play(Write(summary_title))
        self.play(Create(summary_points1), run_time=2)
        self.wait(1)
        self.play(Create(summary_points2), run_time=1)
        self.wait(2)
        self.play(FadeOut(summary_title), FadeOut(summary_points1), FadeOut(summary_points2))

        # 終了
        self.wait(2)
docker-compose exec manim manim -qm demo12_V3DSlides.py V3DSlides

リポジトリ

GitHub - Sunwood-ai-labs/Manim-Examples-Docker
Contribute to Sunwood-ai-labs/Manim-Examples-Docker development by creating an account on GitHub.

コメント

タイトルとURLをコピーしました