diff --git a/AI/Mainm/L1.py b/AI/Mainm/L1.py new file mode 100644 index 00000000..bb092070 --- /dev/null +++ b/AI/Mainm/L1.py @@ -0,0 +1,17 @@ +from manim import * +class NameOfAnimation(Scene): + def construct(self): + #创建矩形,设置边颜色和透明度,填充颜色和透明度 + box = Rectangle(stroke_color=GREEN, + stroke_opacity=0.7, fill_color = RED_B, + fiIl _opacity = 0.5, height=1, width=1) + #无动画添加到场景中 + self.add(box) + #2s内向右移动两个单位 + self.play(box.animate.shift(RIGHT*2), run time=2) + #向上移动三个单位 + self.play(box.animate.shift(UP*3), run time=2) + #向下自动五个单位向左移动5个单位 + self.play(box.animate.shift(DOWN*5+LEFT*5), run_time=2) + #向上移动1.5单位向右移动一个单位 + self.play(box.animate.shift(UP*1.5+RIGHT*1), run time=2) diff --git a/AI/Manim/BoxAnimation.py b/AI/Manim/BoxAnimation.py new file mode 100644 index 00000000..1070f9d9 --- /dev/null +++ b/AI/Manim/BoxAnimation.py @@ -0,0 +1,63 @@ +# 导入Manim核心库 +from manim import * +# 导入Manim配置模块 +import manim + + +# 动画场景类必须继承自Scene +class BoxAnimation(Scene): + # construct方法是所有Manim动画的入口点 + def construct(self): + """ + 创建并动画移动一个矩形 + 步骤: + 1. 创建带样式的矩形 + 2. 分步骤进行位移动画 + """ + # 创建矩形对象 + box = Rectangle( + stroke_color=GREEN, # 边框颜色设置为绿色 + stroke_opacity=0.7, # 边框透明度70% + fill_color=RED_B, # 填充颜色使用红色系B版本 + fill_opacity=0.5, # 填充透明度50% + height=1, # 高度1个单位(Manim默认坐标单位) + width=1 # 宽度1个单位 + ) + + # 将矩形直接添加到场景(无动画) + self.add(box) + + # 第一个动画:2秒内向右移动2个单位 + self.play(box.animate.shift(RIGHT * 2), run_time=2) + + # 第二个动画:2秒内向上移动3个单位 + self.play(box.animate.shift(UP * 3), run_time=2) + + # 第三个动画:2秒内向左下移动(组合位移) + self.play(box.animate.shift(DOWN * 5 + LEFT * 5), run_time=2) + + # 第四个动画:2秒内向右上微调位置 + self.play(box.animate.shift(UP * 1.5 + RIGHT * 1), run_time=2) + + +# 当直接运行本脚本时执行以下代码 +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 = BoxAnimation() + # 执行渲染流程(包含文件生成和预览) + scene.render() \ No newline at end of file diff --git a/AI/Manim/GouGyu.py b/AI/Manim/GouGyu.py new file mode 100644 index 00000000..f023b684 --- /dev/null +++ b/AI/Manim/GouGyu.py @@ -0,0 +1,117 @@ +from manim import * + +class ClearProof(Scene): + def construct(self): + config.frame_width = 12.8 + config.frame_height = 10.24 + colors = { + "a": "#4D9DE0", + "b": "#E15554", + "c": "#3BB273", + "bg": "#1E1E1E", + "text": "#FFFFFF" + } + self.camera.background_color = colors["bg"] + a, b = 3, 4 # 直角边长度 + c = 5 # 斜边长度 + + # ========== 第一步:初始构造 ========== + step1 = Text("构造直角三角形", font_size=36, color=colors["text"]).to_edge(UP) + tri = Polygon([-4, -2, 0], [2, -2, 0], [-4, 2, 0], + color=colors["text"], stroke_width=4) + labels = VGroup( + MathTex("a", color=colors["a"]).next_to(tri.get_bottom(), DOWN, buff=0.3), + MathTex("b", color=colors["b"]).next_to(tri.get_left(), LEFT, buff=0.3), + MathTex("c", color=colors["c"]).move_to(tri.get_vertices()[2] + UR*0.5) + ) + + self.play(Write(step1), run_time=1.5) + self.play(Create(tri), run_time=2) + self.play(LaggedStart(*[Write(l) for l in labels], lag_ratio=0.4)) + self.wait(2) + + # ========== 第二步:构建正方形 ========== + step2 = Text("构建边长的正方形", font_size=36, color=colors["text"]).to_edge(UP) + square_a = Square(a, color=colors["a"], fill_opacity=0.3).next_to(tri, RIGHT, buff=2) + square_b = Square(b, color=colors["b"], fill_opacity=0.3).next_to(tri, LEFT, buff=2) + square_c = Square(c, color=colors["c"], fill_opacity=0.3).move_to(ORIGIN + DOWN*1.5) + + self.play( + ReplacementTransform(step1, step2), + DrawBorderThenFill(square_a), + DrawBorderThenFill(square_b), + run_time=2 + ) + self.wait(1.5) + + # ========== 第三步:分割图形 ========== + step3 = Text("分割正方形为可重组部件", font_size=36, color=colors["text"]).to_edge(UP) + # 分割a²正方形 + a_pieces = VGroup( + tri.copy().set_fill(colors["a"], 0.3), + tri.copy().rotate(PI/2).set_fill(colors["a"], 0.3).shift(RIGHT*a) + ) + # 分割b²正方形 + b_pieces = VGroup( + tri.copy().rotate(-PI/2).set_fill(colors["b"], 0.3), + tri.copy().rotate(PI).set_fill(colors["b"], 0.3).shift(LEFT*b) + ) + + self.play( + ReplacementTransform(step2, step3), + square_a.animate.set_fill(opacity=0), + square_b.animate.set_fill(opacity=0), + LaggedStart( + Transform(square_a, a_pieces), + Transform(square_b, b_pieces), + lag_ratio=0.5 + ), + run_time=3 + ) + self.wait(2) + + # ========== 第四步:重组图形 ========== + step4 = Text("重组部件构成大正方形", font_size=36, color=colors["text"]).to_edge(UP) + # 计算重组后的位置 + final_positions = [ + [-c/2, -c/2 -1.5, 0], [c/2, -c/2 -1.5, 0], + [c/2, c/2 -1.5, 0], [-c/2, c/2 -1.5, 0] + ] + # 创建重组动画 + animations = [] + for i, piece in enumerate(a_pieces): + animations.append(piece.animate.move_to(final_positions[i])) + for i, piece in enumerate(b_pieces): + animations.append(piece.animate.move_to(final_positions[i+2])) + + self.play( + ReplacementTransform(step3, step4), + LaggedStart(*animations, lag_ratio=0.3), + FadeIn(square_c, shift=UP), + run_time=4 + ) + self.wait(2) + + # ========== 第五步:面积等式 ========== + step5 = Text("面积守恒证明定理", font_size=36, color=colors["text"]).to_edge(UP) + equation = MathTex( + "a^2", "+", "b^2", "=", "c^2", + substrings_to_isolate=["a^2", "b^2", "c^2"] + ).scale(1.5).set_color_by_tex("a^2", colors["a"]).set_color_by_tex("b^2", colors["b"]).set_color_by_tex("c^2", colors["c"]) + + self.play( + ReplacementTransform(step4, step5), + FadeOut(VGroup(a_pieces, b_pieces, square_c)), + Write(equation), + run_time=2 + ) + self.wait(3) + + # ========== 最终总结 ========== + conclusion = Text("勾股定理得证!", font_size=48, color=colors["c"]) + self.play( + FadeOut(equation), + FadeOut(step5), + Write(conclusion, run_time=2) + ) + self.wait(3) \ No newline at end of file diff --git a/AI/Manim/__pycache__/GouGyu.cpython-310.pyc b/AI/Manim/__pycache__/GouGyu.cpython-310.pyc new file mode 100644 index 00000000..bfd89741 Binary files /dev/null and b/AI/Manim/__pycache__/GouGyu.cpython-310.pyc differ diff --git a/AI/Manim/custom_output/videos/BoxAnimation/480p15/BoxAnimation.mp4 b/AI/Manim/custom_output/videos/BoxAnimation/480p15/BoxAnimation.mp4 new file mode 100644 index 00000000..da3c1891 Binary files /dev/null and b/AI/Manim/custom_output/videos/BoxAnimation/480p15/BoxAnimation.mp4 differ diff --git a/AI/Manim/custom_output/videos/BoxAnimation/480p15/partial_movie_files/BoxAnimation/1185818338_2357871401_3733939583.mp4 b/AI/Manim/custom_output/videos/BoxAnimation/480p15/partial_movie_files/BoxAnimation/1185818338_2357871401_3733939583.mp4 new file mode 100644 index 00000000..df610b36 Binary files /dev/null and b/AI/Manim/custom_output/videos/BoxAnimation/480p15/partial_movie_files/BoxAnimation/1185818338_2357871401_3733939583.mp4 differ diff --git a/AI/Manim/custom_output/videos/BoxAnimation/480p15/partial_movie_files/BoxAnimation/624642324_1528713618_3733939583.mp4 b/AI/Manim/custom_output/videos/BoxAnimation/480p15/partial_movie_files/BoxAnimation/624642324_1528713618_3733939583.mp4 new file mode 100644 index 00000000..43e0ba17 Binary files /dev/null and b/AI/Manim/custom_output/videos/BoxAnimation/480p15/partial_movie_files/BoxAnimation/624642324_1528713618_3733939583.mp4 differ diff --git a/AI/Manim/custom_output/videos/BoxAnimation/480p15/partial_movie_files/BoxAnimation/624642324_1659542893_3733939583.mp4 b/AI/Manim/custom_output/videos/BoxAnimation/480p15/partial_movie_files/BoxAnimation/624642324_1659542893_3733939583.mp4 new file mode 100644 index 00000000..dc8eba7d Binary files /dev/null and b/AI/Manim/custom_output/videos/BoxAnimation/480p15/partial_movie_files/BoxAnimation/624642324_1659542893_3733939583.mp4 differ diff --git a/AI/Manim/custom_output/videos/BoxAnimation/480p15/partial_movie_files/BoxAnimation/624642324_3298254401_3733939583.mp4 b/AI/Manim/custom_output/videos/BoxAnimation/480p15/partial_movie_files/BoxAnimation/624642324_3298254401_3733939583.mp4 new file mode 100644 index 00000000..8bc142a6 Binary files /dev/null and b/AI/Manim/custom_output/videos/BoxAnimation/480p15/partial_movie_files/BoxAnimation/624642324_3298254401_3733939583.mp4 differ diff --git a/AI/Manim/custom_output/videos/BoxAnimation/480p15/partial_movie_files/BoxAnimation/partial_movie_file_list.txt b/AI/Manim/custom_output/videos/BoxAnimation/480p15/partial_movie_files/BoxAnimation/partial_movie_file_list.txt new file mode 100644 index 00000000..484ab5ca --- /dev/null +++ b/AI/Manim/custom_output/videos/BoxAnimation/480p15/partial_movie_files/BoxAnimation/partial_movie_file_list.txt @@ -0,0 +1,5 @@ +# This file is used internally by FFMPEG. +file 'file:D:/dsWork/QingLong/AI/Manim/custom_output/videos/BoxAnimation/480p15/partial_movie_files/BoxAnimation/1185818338_2357871401_3733939583.mp4' +file 'file:D:/dsWork/QingLong/AI/Manim/custom_output/videos/BoxAnimation/480p15/partial_movie_files/BoxAnimation/624642324_3298254401_3733939583.mp4' +file 'file:D:/dsWork/QingLong/AI/Manim/custom_output/videos/BoxAnimation/480p15/partial_movie_files/BoxAnimation/624642324_1528713618_3733939583.mp4' +file 'file:D:/dsWork/QingLong/AI/Manim/custom_output/videos/BoxAnimation/480p15/partial_movie_files/BoxAnimation/624642324_1659542893_3733939583.mp4' diff --git a/AI/Manim/custom_output/videos/L1/480p15/BoxAnimation.mp4 b/AI/Manim/custom_output/videos/L1/480p15/BoxAnimation.mp4 new file mode 100644 index 00000000..da3c1891 Binary files /dev/null and b/AI/Manim/custom_output/videos/L1/480p15/BoxAnimation.mp4 differ diff --git a/AI/Manim/custom_output/videos/L1/480p15/partial_movie_files/BoxAnimation/1185818338_2357871401_3733939583.mp4 b/AI/Manim/custom_output/videos/L1/480p15/partial_movie_files/BoxAnimation/1185818338_2357871401_3733939583.mp4 new file mode 100644 index 00000000..df610b36 Binary files /dev/null and b/AI/Manim/custom_output/videos/L1/480p15/partial_movie_files/BoxAnimation/1185818338_2357871401_3733939583.mp4 differ diff --git a/AI/Manim/custom_output/videos/L1/480p15/partial_movie_files/BoxAnimation/624642324_1528713618_3733939583.mp4 b/AI/Manim/custom_output/videos/L1/480p15/partial_movie_files/BoxAnimation/624642324_1528713618_3733939583.mp4 new file mode 100644 index 00000000..43e0ba17 Binary files /dev/null and b/AI/Manim/custom_output/videos/L1/480p15/partial_movie_files/BoxAnimation/624642324_1528713618_3733939583.mp4 differ diff --git a/AI/Manim/custom_output/videos/L1/480p15/partial_movie_files/BoxAnimation/624642324_1659542893_3733939583.mp4 b/AI/Manim/custom_output/videos/L1/480p15/partial_movie_files/BoxAnimation/624642324_1659542893_3733939583.mp4 new file mode 100644 index 00000000..dc8eba7d Binary files /dev/null and b/AI/Manim/custom_output/videos/L1/480p15/partial_movie_files/BoxAnimation/624642324_1659542893_3733939583.mp4 differ diff --git a/AI/Manim/custom_output/videos/L1/480p15/partial_movie_files/BoxAnimation/624642324_3298254401_3733939583.mp4 b/AI/Manim/custom_output/videos/L1/480p15/partial_movie_files/BoxAnimation/624642324_3298254401_3733939583.mp4 new file mode 100644 index 00000000..8bc142a6 Binary files /dev/null and b/AI/Manim/custom_output/videos/L1/480p15/partial_movie_files/BoxAnimation/624642324_3298254401_3733939583.mp4 differ diff --git a/AI/Manim/custom_output/videos/L1/480p15/partial_movie_files/BoxAnimation/partial_movie_file_list.txt b/AI/Manim/custom_output/videos/L1/480p15/partial_movie_files/BoxAnimation/partial_movie_file_list.txt new file mode 100644 index 00000000..4bc5d97d --- /dev/null +++ b/AI/Manim/custom_output/videos/L1/480p15/partial_movie_files/BoxAnimation/partial_movie_file_list.txt @@ -0,0 +1,5 @@ +# This file is used internally by FFMPEG. +file 'file:D:/dsWork/QingLong/AI/Manim/custom_output/videos/L1/480p15/partial_movie_files/BoxAnimation/1185818338_2357871401_3733939583.mp4' +file 'file:D:/dsWork/QingLong/AI/Manim/custom_output/videos/L1/480p15/partial_movie_files/BoxAnimation/624642324_3298254401_3733939583.mp4' +file 'file:D:/dsWork/QingLong/AI/Manim/custom_output/videos/L1/480p15/partial_movie_files/BoxAnimation/624642324_1528713618_3733939583.mp4' +file 'file:D:/dsWork/QingLong/AI/Manim/custom_output/videos/L1/480p15/partial_movie_files/BoxAnimation/624642324_1659542893_3733939583.mp4' diff --git a/AI/Manim/安装Manim.txt b/AI/Manim/安装Manim.txt index fbfdacd8..d4ab5da8 100644 --- a/AI/Manim/安装Manim.txt +++ b/AI/Manim/安装Manim.txt @@ -31,9 +31,22 @@ manim --version # 8、测试 +conda activate manim-env # 最简单的方框和圆 manim -pql D:\dsWork\QingLong\AI\Manim\simple_example.py SimpleScene # 平方差公式 -manim -pql D:\dsWork\QingLong\AI\Manim\difference_of_squares.py SquareDifference \ No newline at end of file +manim -pql D:\dsWork\QingLong\AI\Manim\difference_of_squares.py SquareDifference + +# 勾股定理 +manim -pql D:\dsWork\QingLong\AI\Manim\GouGyu.py GouGu + +# 提示词: +请写一段manim脚本(我使用的版本是:Manim Community v0.19.0),用通俗易懂的方式详细介绍 公式定理。 +每一步都先显示中文Text提示,然后展示图形或公式(公式不要出现中文,避免编译报错)。 +如果画面元素过多,请在确保保留关键元素的情况下,移除其他元素再继续讲解,避免公式和图像重叠。 +尽量做到循序渐进,动画流畅,同时让影片速度慢一点,最好在每一步完成后稍作短暂停留。 + + +确认无误后,输入manim -pqh script.py​生成高画质动画并播放。 \ No newline at end of file