You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
2.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 导入Manim核心库
from manim import *
# 导入Manim配置模块
import manim
class FittingObjects(Scene):
def construct(self):
# 坐标系放在左侧边缘
axes = Axes(x_range=[-3, 3, 1], y_range=[-3, 3, 1], x_length=6, y_length=6)
# 坐标系距离左侧有0.5的缓冲距离
axes.to_edge(LEFT, buff=0.5)
# 圆,线宽颜色,填充颜色和透明度
circle = Circle(stroke_width=6, stroke_color=YELLOW, fill_color=RED, fill_opacity=0.8)
# 圆的宽度是2位置在右下角无缓冲距离
circle.set_width(2).to_edge(DR, buff=0)
# 创建三角形高度2位置右下3.3处
triangle = Triangle(stroke_color=ORANGE, stroke_width=10, fill_color=GREY).set_height(2).shift(
DOWN * 3 + RIGHT * 3)
# 创建动画 画坐标系
self.play(Write(axes))
# 创建动画 画线然后填充圆
self.play(DrawBorderThenFill(circle))
# 形态动画 圆变化宽度
self.play(circle.animate.set_width(1))
# 转变动画 将圆向三角转变
self.play(Transform(circle, triangle), run_time=3)
# 当直接运行本脚本时执行以下代码
if __name__ == '__main__':
"""
配置渲染参数并执行场景渲染
等效命令行命令:
manim -pql -o custom_output 当前文件.py BoxAnimation
"""
# 配置字典说明:
config = {
"quality": "low_quality", # 渲染质量等级low_quality对应480p
"preview": True, # 渲染完成后自动打开播放器
"input_file": __file__, # 指定输入文件为当前文件
"media_dir": "./custom_output" # 自定义输出目录默认在media/
}
# 使用临时配置渲染场景配置只在with块内有效
with manim.tempconfig(config):
# 实例化场景类
scene = FittingObjects()
# 执行渲染流程(包含文件生成和预览)
scene.render()