main
黄海 5 months ago
parent e48a8e7f4e
commit e0e4523508

@ -0,0 +1,82 @@
import manim
from manim import *
from manim import ValueTracker # 需要显式导入ValueTracker
class CircleAnimation(Scene):
def construct(self):
# 初始化半径跟踪器
r = ValueTracker(0.5)
# 修正1使用Circle类首字母大写
circle = always_redraw(lambda: Circle(
radius=r.get_value(),
stroke_color=YELLOW,
stroke_width=5
))
# 修正2补全Line的闭合括号
line_radius = always_redraw(lambda: Line(
start=circle.get_center(),
end=circle.get_bottom(),
stroke_color=RED_B,
stroke_width=10
))
# 修正3补全Line参数和闭合括号
line_circumference = always_redraw(lambda: Line(
start=ORIGIN, end=RIGHT # 需要指定起点终点
).set_length(2 * PI * r.get_value()) # 正确周长公式
.next_to(circle, DOWN, buff=0.2)
.set_stroke(color=YELLOW, width=5))
# 修正4补全Polygon参数和颜色设置
triangle = always_redraw(lambda: Polygon(
circle.get_top(),
circle.get_left(),
circle.get_right(),
fill_color=GREEN_C,
fill_opacity=0.5 # 添加填充透明度
))
# 修正5正确拼写LaggedStart补全参数括号
self.play(LaggedStart(
Create(circle),
DrawBorderThenFill(line_radius),
DrawBorderThenFill(triangle),
run_time=4,
lag_ratio=0.75
))
# 修正6正确转换动画
self.play(ReplacementTransform(
circle.copy().clear_updaters(), # 移除持续更新
line_circumference
), run_time=2)
# 半径变化动画
self.play(r.animate.set_value(2), run_time=5)
self.wait()
# 当直接运行本脚本时执行以下代码
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 = CircleAnimation()
# 执行渲染流程(包含文件生成和预览)
scene.render()

@ -0,0 +1,5 @@
# This file is used internally by FFMPEG.
file 'file:D:/dsWork/QingLong/AI/Manim/custom_output/videos/L4Tute4/480p15/partial_movie_files/CircleAnimation/1185818338_2244466868_2358810818.mp4'
file 'file:D:/dsWork/QingLong/AI/Manim/custom_output/videos/L4Tute4/480p15/partial_movie_files/CircleAnimation/624642324_3394056140_2805240298.mp4'
file 'file:D:/dsWork/QingLong/AI/Manim/custom_output/videos/L4Tute4/480p15/partial_movie_files/CircleAnimation/624642324_2631639100_3067771568.mp4'
file 'file:D:/dsWork/QingLong/AI/Manim/custom_output/videos/L4Tute4/480p15/partial_movie_files/CircleAnimation/624642324_667144672_3888841989.mp4'
Loading…
Cancel
Save