# 导入Manim核心库 from manim import * 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)