Files
dsProject/dsLightRag/Manim/L2_FittingObjects.py
2025-08-14 15:45:08 +08:00

27 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 导入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)