Skip to content

Latest commit

 

History

History
164 lines (111 loc) · 3.79 KB

README_zh_CN.md

File metadata and controls

164 lines (111 loc) · 3.79 KB

logo

MIT License

English | >简体中文<

介绍

JAnim 是一个用于创建流畅动画的库

受到 manim 的启发

介绍视频:https://www.bilibili.com/video/BV17s42137SJ/

示例



亮点

程序化动画

class BubbleSort(Timeline):
    def construct(self):
        # define items
        heights = np.linspace(1.0, 6.0, 5)
        np.random.seed(123456)
        np.random.shuffle(heights)
        rects = [
            Rect(1, height,
                 fill_alpha=0.5)
            for height in heights
        ]

        group = Group(*rects)
        group.points.arrange(aligned_edge=DOWN)

        # do animations
        self.show(group)

        for i in range(len(heights) - 1, 0, -1):
            for j in range(i):
                rect1, rect2 = rects[j], rects[j + 1]

                self.play(
                    rect1.anim.color.set(BLUE),
                    rect2.anim.color.set(BLUE),
                    duration=0.15
                )

                if heights[j] > heights[j + 1]:
                    x1 = rect1.points.box.x
                    x2 = rect2.points.box.x

                    self.play(
                        rect1.anim.points.set_x(x2),
                        rect2.anim.points.set_x(x1),
                        duration=0.3
                    )

                    heights[[j, j + 1]] = heights[[j + 1, j]]
                    rects[j], rects[j + 1] = rect2, rect1

                self.play(
                    rect1.anim.color.set(WHITE),
                    rect2.anim.color.set(WHITE),
                    duration=0.15
                )

修改代码,立即更新

随意控制预览进度

安装

⚠️ macOS 无法使用 JAnim

JAnim 运行在 Python 3.12 及更高版本,并且需要 OpenGL 4.3 及更高版本

你可以通过以下命令直接安装 JAnim

pip install janim

来安装在 pypi 上发布的最新版本。或者,为了跟上最新的开发进度并编辑源代码,你可以通过以下命令克隆此仓库

git clone https://github.com/jkjkil4/JAnim.git
cd JAnim
pip install -e .

另外,还需要安装其他软件依赖:

  • 要生成视频文件,请安装 ffmpeg.
  • 要使用 Typst,请安装 typst.

使用 JAnim

你可以使用如下的命令来查看示例

janim examples

文档教程页面提供了一个简要的入门指南(注:你可以在文档的左下角更改语言)

License

MIT license