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.
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 )