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.

54 lines
2.3 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 Updaters(Scene):
def construct(self):
# 创建圆角矩型线宽8线色白填充色蓝宽4.5高2位置在上3左4
rectangle = RoundedRectangle(stroke_width=8, stroke_color=WHITE, fill_color=BLUE_B, width=4.5, height=2).shift(
UP * 3 + LEFT * 4)
# 创建数学公式设置渐变色设置高度1.5
mathtext = MathTex("\\frac{3}{4} = 0.75"
).set_color_by_gradient(GREEN, PINK).set_height(1.5)
# 数学公式位置放在圆角矩型中间
mathtext.move_to(rectangle.get_center())
# 给公式添加一个更新器,公式的位置保持在圆角矩型中间
mathtext.add_updater(lambda x: x.move_to(rectangle.get_center()))
# 开始动画播放
# 动画,矩形出现方式
self.play(FadeIn(rectangle))
# 动画 公式出现
self.play(Write(mathtext))
# 动画矩形移动向右1.5向下5矩形移动时公式跟随移动
self.play(rectangle.animate.shift(RIGHT * 1.5 + DOWN * 5), run_time=6)
# 等待上面动画完成
self.wait()
# 删除公式的更新器
mathtext.clear_updaters()
# 动画矩形向左2向上1公式不跟随矩形移动
self.play(rectangle.animate.shift(LEFT * 2 + UP * 1), run_time=6)
# 当直接运行本脚本时执行以下代码
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 = Updaters()
# 执行渲染流程(包含文件生成和预览)
scene.render()