京东网站开发技术,织梦网站如何做404,帮建网站,渠道游戏官网相信很多同学就算没听过3Blue1Brown#xff0c;也一定曾看过他们出品的视频#xff0c;其从独特的视觉角度解说各种数学概念#xff0c;内容包括线性代数、微积分、神经网络、傅里叶变换以及四元数等晦涩难懂的知识点。例如最火的《线性代数本质》系列视频。
那么这些视频是…
相信很多同学就算没听过3Blue1Brown也一定曾看过他们出品的视频其从独特的视觉角度解说各种数学概念内容包括线性代数、微积分、神经网络、傅里叶变换以及四元数等晦涩难懂的知识点。例如最火的《线性代数本质》系列视频。
那么这些视频是如何制作的呢
这里需要引入的是Python的Manim视频支持引擎——专门用于支持数学可视化的媒体引擎通过Manim并结合Python编程就可以实现3Blue1Brown的视频效果。
什么是Python
在当今备受推崇的大数据技术和人工智能技术领域Python一直是一门备受瞩目的编程语言。它长期占据着TIOBE公布的编程语言排行榜的榜首位置。业界也一直流传着一句话“人生苦短我用Python”。Python作为一门计算机编程语言具有独特的优势可以总结为以下三个特点简洁性、易读性和可扩展性。
简洁性 Python是一门非常简洁的脚本语言。很多时候只需一行代码就能实现复杂的功能。比如下面这行代码就能打印出一个九九乘法表。这种简洁性使得你能够将注意力集中在解决问题上而不必花费过多时间去理解语言本身。
易读性 Python的语法风格清晰简约易于阅读。有时候它就像人类说话一样自然简单没有过多的修饰。
可扩展性 Python最初的设计就注重可扩展性它并没有将所有的特性和功能集成到核心语言中。Python提供了丰富的API和工具以及众多第三方库让你可以灵活扩展其功能。你可以根据需要选择合适的库来解决问题这使得Python非常适合各种不同的应用场景。
什么是manim manim视频 manim是一个Python第三方库全称是mathematical animation engine数学动画引擎。它是由斯坦福大学数学系学生Grant Sanderson在其YouTube频道3Blue1Brown上创建的。manim用于解说线性代数、微积分、神经网络、黎曼猜想、傅里叶变换以及四元数等数学概念。
manim因其精美的动画制作和独特的解释角度而广受关注并吸引了越来越多的读者参与其中共同贡献内容。manim经历了两个版本的迭代。第一代是ManimCairo这是较早的版本Grant Sanderson早期的项目都是在此版本中编译的。它使用cairo库作为渲染引擎。第二代是ManimGL由Grant Sanderson等人开发的最新版本。该版本的最大改进是采用更强大的OpenGL库进行渲染。
此外还有ManimCEmanim社区版也使用OpenGL进行渲染。
manim使你能够以编程的方式创建精确的数学图形、动画和场景。与传统的几何画板等绘图软件不同manim提供了一种全新的思路“所思即可得”。它能够实现非常精准的绘制。在manim的世界中你可以体验到一切皆可设置的感觉。颜色、粗细、长度、角度、时长、播放方式等均可通过设置来完成这使你能够制作出具有个性化的数学动画。
版本渲染引擎库ManimCairoCairomanimlibManimGLOpenGLmanimglManimCEOpenGLmanim 如何来运行Manim 安装 Manim 首先您需要安装 Python 和一些依赖项。然后您可以通过以下命令使用 pip 安装 Manim pip install manim创建动画 创建一个 Python 脚本并使用 Manim 中的类来定义您的动画场景和对象。 运行 Manim 在命令行中转到包含您的 Python 脚本的目录并使用以下命令来运行 Manim manim your_script.py YourSceneName -p -ql其中your_script.py 是您的 Python 脚本的文件名YourSceneName 是您定义的场景名称。
这样Manim 就会开始渲染动画。请注意Manim 的运行可能需要一定的时间具体取决于动画内容和计算机性能。
用 Manim 绘制图形
首先需要引入 Manim 库然后将需要绘制的内容封装到一个类(class)里面。
from manim import *对于编辑好的程序文件例如christmas-intro.py文件需要在同一个文件夹下运行命令来运行程序命令格式如下
manim -pql christmas-intro.py DemoSquare上面的命令行中
manim 是运行程序的主要标志用语p 表示程序运行后会进行预览图片或视频ql 表示低质量quality low, 其他的选项有 -ql, -qm, -qh, -qk, 分别表示 低质量、正常质量、高质量、4K质量christmas-intro.py 是py代码文件DemoSquare 是 py代码文件中的一个类
命令行中还有其他许多参数可以设置可以通过社区版的支持文档来进一步了解。
几个常见方程的示例 from manim import *class QuadraticSurface(ThreeDScene):def construct(self):resolution_fa 24 #曲面样本数axes ThreeDAxes() #3维度笛卡尔直角坐标系self.set_camera_orientation(phi 75*DEGREES, theta 45*DEGREES) #phi是竖直方向岔开的角度theta是水平面岔开的角度def paramsFunc(u, v): #参数方程x uy 1/2*u**2z vreturn np.array([x, y, z])quadratic_surface Surface(paramsFunc,resolution (resolution_fa, resolution_fa), #分辨率u_range[-2.5, 2.5], #参数u的范围v_range[-1, 1], #参数v的范围fill_opacity 0.5 #透明度) #二次曲面self.add(axes) #添加坐标轴self.wait() #停留一秒self.play(Write(quadratic_surface), run_time 10) #绘制二次曲面self.begin_3dillusion_camera_rotation(rate 2) #摇晃rotation illusionself.wait(PI) #摇晃时长self.stop_3dillusion_camera_rotation() #停止摇晃with tempconfig({quality:medium_quality, preview:True}):scene QuadraticSurface()scene.render()from manim import *class QuadraticSurface(ThreeDScene):def construct(self):resolution_fa 24 #曲面样本数axes ThreeDAxes() #3维度笛卡尔直角坐标系self.set_camera_orientation(phi 75*DEGREES, theta 45*DEGREES) #phi是竖直方向岔开的角度theta是水平面岔开的角度def paramsFunc(u, v): #参数方程x np.sqrt(2)* np.cos(TAU*u)*vy np.sqrt(2)* np.sin(TAU*u)*vz vreturn np.array([x, y, z])quadratic_surface Surface(paramsFunc,resolution (resolution_fa, resolution_fa), #分辨率u_range[-2, 2], #参数u的范围v_range[-2, 2], #参数v的范围fill_opacity 0.5 #透明度) #二次曲面self.add(axes) #添加坐标轴self.wait() #停留一秒self.play(Write(quadratic_surface), run_time 10) #绘制二次曲面self.begin_3dillusion_camera_rotation(rate 2) #摇晃rotation illusionself.wait(PI) #摇晃时长self.stop_3dillusion_camera_rotation() #停止摇晃with tempconfig({quality:medium_quality, preview:True}):scene QuadraticSurface()scene.render()manin安装教程
https://docs.manim.community/en/stable/installation.html社区版 Manim教程合集 https://www.bilibili.com/video/BV1W4411Z7Zt/?vd_source3ef6540f8473c7367625a53b7b77fd66
Manim官方文档 https://docs.manim.org.cn/cairo-backend/getting_started/index.html
from manim import *class QuadraticSurface(ThreeDScene):def construct(self):resolution_fa 24 #曲面样本数axes ThreeDAxes() #3维度笛卡尔直角坐标系self.set_camera_orientation(phi 75*DEGREES, theta 45*DEGREES) #phi是竖直方向岔开的角度theta是水平面岔开的角度def paramsFunc(u, v): #参数方程x np.sinh(u)*np.cos(v)y np.sinh(u)*np.sin(v)z np.cosh(u)return np.array([x, y, z])quadratic_surface Surface(paramsFunc,resolution (resolution_fa, resolution_fa), #分辨率u_range[-1.5, 1.5], #参数u的范围v_range[-PI, PI], #参数v的范围fill_opacity 0.5 #透明度) #二次曲面def paramsFunc1(u, v): #参数方程x np.sinh(u)*np.cos(v)y np.sinh(u)*np.sin(v)z np.cosh(u)return np.array([x, y, -z])quadratic_surface1 Surface(paramsFunc1,resolution (resolution_fa, resolution_fa), #分辨率u_range[-1.5, 1.5], #参数u的范围v_range[-PI, PI], #参数v的范围fill_opacity 0.5 #透明度) #二次曲面self.add(axes) #添加坐标轴self.wait() #停留一秒self.play(Write(quadratic_surface), run_time 10) #绘制二次曲面self.play(Write(quadratic_surface1), run_time 10) #绘制二次曲面self.begin_3dillusion_camera_rotation(rate 2) #摇晃rotation illusionself.wait(PI) #摇晃时长self.stop_3dillusion_camera_rotation() #停止摇晃with tempconfig({quality:medium_quality, preview:True}):scene QuadraticSurface()scene.render()版本说明
对于 Manim 的初学者使用 Manim 时对于其版本的选择还是有些需要注意的地方。
不同版本的代码、教程等还是有稍许差异的。
目前 Manim 主要有三个版本 3b1b 旧版3blue1brown 自己维护的版本使用 Cairo 作为后端
3b1b 新版3blue1brown 自己维护的版本使用 OpenGL 和 moderngl 来进行 GPU 渲染优点是速度快
Manim 社区版社区版是2020年下半年才出来的版本目前主要是 Manim 旧版的衍生更新更活跃有很好的文档和社区支持。当然随着社区版的迭代更新目前 3b1b 新版 的某些特性也在逐步容纳进来。
关于这几个版本如何选择的建议
如果你是新接触这个工具的建议可以从社区版开始主要是社区版的文档教程比较齐全其迭代的频率更快。 如果你是 Python 或者其他编程领域的资深人士想体自己动手深入理解并优化这个工具可以使用 3b1b 新版
Manim 的安装
在 Manim 3b1b 版本 和 社区版均提供了如何安装的文档
3b1b 新版的安装文档https://github.com/3b1b/manim 社区版的安装文档https://docs.manim.community/en/stable/installation.html
安装ffmpeg
FFmpeg是一个开源的跨平台音视频处理工具可以用来录制、转换和流式传输音视频内容。它包括一组库和程序可以处理多种不同格式的音频、视频和图片文件。FFmpeg支持几乎所有主流的音视频格式因此被广泛应用于多媒体处理领域。
FFmpeg提供了丰富的功能包括但不限于
音视频编解码可以对音频和视频进行编码压缩和解码解压支持众多编解码器。格式转换可以将音视频文件从一个格式转换为另一个格式例如从MP4转换为AVI。剪辑和编辑可以对音视频文件进行剪辑、合并、分离等操作。流媒体处理支持流式传输音视频内容适用于网络直播、视频会议等场景。屏幕录制可以用来录制屏幕内容并保存为视频文件。
由于其强大的功能和灵活性FFmpeg被广泛用于视频处理、视频转码、音频处理等各种多媒体应用中。同时FFmpeg也是许多视频播放器、编辑软件以及流媒体平台的重要组件之一。
安装FFmpeg可以通过命令行或者图形界面进行操作以下是在Windows和MacOS上安装FFmpeg的基本步骤
在Windows上安装FFmpeg 下载FFmpeg 访问FFmpeg官方网站或Windows Builds by BtbN下载最新版本的静态链接的可执行文件。 解压文件 将下载的压缩包解压到你想要安装的位置。 设置环境变量可选 将FFmpeg的bin目录添加到系统的PATH环境变量中这样就可以在命令行中直接访问FFmpeg。 测试安装 打开命令提示符Win R输入cmd回车输入以下命令来检查FFmpeg是否成功安装ffmpeg -version在MacOS上安装FFmpeg 使用Homebrew安装推荐 打开终端运行以下命令安装Homebrew/bin/bash -c $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)然后运行以下命令来安装FFmpegbrew install ffmpeg测试安装 在终端中输入以下命令来检查FFmpeg是否成功安装ffmpeg -version在Linux上安装FFmpeg 使用包管理器安装 对于大多数Linux发行版可以使用其包管理器来安装FFmpeg。例如在Ubuntu上可以使用以下命令sudo apt-get update
sudo apt-get install ffmpeg测试安装 在终端中输入以下命令来检查FFmpeg是否成功安装ffmpeg -version验证安装
无论在哪个操作系统上安装验证安装步骤都是一样的。只需要在命令行或终端中输入以下命令
ffmpeg -version如果安装成功会显示FFmpeg的版本信息。这样就可以确认FFmpeg已经成功安装并且可以在系统中正常运行了。 安装Latex
LaTeX是一种专业的排版系统常用于撰写学术论文、书籍、报告和演示文稿。与常见的文字处理软件如Microsoft Word不同LaTeX使用的是一种“标记语言”用户需要通过输入特定的命令和标记来控制文档的格式、结构和样式。
LaTeX最初是由著名计算机科学家Leslie Lamport开发的它建立在TeX排版系统之上并提供了一系列功能强大的工具和环境使用户能够轻松地创建高质量的文档。
使用LaTeX编写文档的优势包括
专业的排版效果LaTeX能够生成高质量、专业水准的文档排版特别适合于学术论文、书籍等内容丰富的文档。具有强大的数学公式排版能力LaTeX在排版数学公式和符号方面非常出色被广泛应用于数学、物理等领域的文档撰写。跨平台性LaTeX在不同操作系统上都可以运行并且生成的文档格式稳定、可靠。
虽然学习曲线较陡但一旦熟悉了LaTeX的基本语法和命令就能够享受到其带来的排版便利和效果。
安装LaTeX可以通过以下步骤进行操作
在Windows上安装LaTeX 下载安装包 访问TeX Users Group或MiKTeX网站下载LaTeX发行版的安装程序。 运行安装程序 双击下载的安装程序按照提示进行安装。 配置编辑器可选 如果你希望使用图形化的编辑器来编写LaTeX文档可以安装一些流行的LaTeX编辑器如TeXstudio、TeXworks等这些编辑器通常会自动检测已安装的LaTeX发行版。 测试安装 打开命令提示符或者你喜欢的LaTeX编辑器新建一个简单的.tex文件输入以下内容并保存\documentclass{article}
\begin{document}
Hello, LaTeX!
\end{document}编译这个文件如果能够生成对应的.pdf文件并且内容显示正常那么LaTeX安装成功了。
在MacOS上安装LaTeX 使用MacTeX安装 下载并安装MacTeX这是专为MacOS准备的LaTeX发行版。你可以在MacTeX官方网站下载最新版本的安装程序。 配置编辑器可选 安装一些流行的LaTeX编辑器如TeXShop、TeXstudio等这些编辑器通常会自动检测已安装的LaTeX发行版。 测试安装 使用编辑器创建一个简单的.tex文件输入上述示例中的内容并进行编译。
在Linux上安装LaTeX 使用包管理器安装 对于大多数Linux发行版可以使用其包管理器来安装LaTeX。例如在Ubuntu上可以使用以下命令sudo apt-get update
sudo apt-get install texlive-full测试安装 使用编辑器创建一个简单的.tex文件输入上述示例中的内容并进行编译。
安装dvisvgm
安装 dvisvgm 可以通过以下步骤进行
Windows 用户
使用 Chocolatey 进行安装 打开命令提示符CMD或 PowerShell并执行以下命令choco install dvisvgmmacOS 用户
使用 Homebrew 进行安装 打开终端并执行以下命令brew install dvisvgmLinux 用户 对于基于 Debian 的系统如 Ubuntu 打开终端并执行以下命令 sudo apt-get install dvisvgm对于基于 Red Hat 的系统如 Fedora 打开终端并执行以下命令 sudo dnf install dvisvgm一旦安装完成您可以在命令行中运行 dvisvgm --version 来验证 dvisvgm 是否成功安装。 利用Manim绘制苹果logo
from manimlib.imports import *
from my_projects.my_utils.boolean_operation import VGroup_get_angle lambda c: np.angle(-c) PI if not c/abs(c) 1 else 0
convert_angle lambda a: a if a0 else a TAUclass Apple_logo(VGroup):CONFIG {scale: 0.25,logo_color: RED_D,logo_stroke: 8,coord_center: DOWN * 1.25,assistent_lines_config: {stroke_width: 2,stroke_color: GREY,},key_lines_config: {stroke_width: 2.5,stroke_color: GREY_E,},step_size: 0.02,create_shape: True,}def __init__(self, **kwargs):VGroup.__init__(self, **kwargs)self.set_key_lines()self.set_outline()if self.create_shape:self.set_logo_shape()def set_key_lines(self):s self.scalecenter self.coord_centerself.c1 Circle(arc_centercenterORIGIN, radius1/2*s, **self.key_lines_config)self.c5_r Circle(arc_centercenter3*s*RIGHT, radius5/2*s, **self.key_lines_config)self.c5_l Circle(arc_centercenter3*s*LEFT, radius5/2*s, **self.key_lines_config)# self.c5_l self.c5_r.copy().flip()self.c8_d Circle(arc_centercenter s * 5.77 * DOWN, radius8/2*s, **self.key_lines_config)self.c13 Circle(arc_centercenter s * 4.73 * UP, radius13/2*s, **self.key_lines_config)self.c8_r Circle(arc_centercenter s * ( 3.48 * RIGHT 7.69 * UP),radius8/2*s, **self.key_lines_config)self.c8_l Circle(arc_centercenter s * (-3.48 * RIGHT 7.69 * UP),radius8/2*s, **self.key_lines_config)self.c3_r Circle(arc_centercenter s * ( 5.9 * RIGHT 2.75 * UP),radius3/2*s, **self.key_lines_config)self.c3_l Circle(arc_centercenter s * (-5.9 * RIGHT 2.75 * UP),radius3/2*s, **self.key_lines_config)self.c24_r Circle(arc_centercenter s * ( 3.89 * RIGHT 6.54 * UP),radius24/2*s, **self.key_lines_config)self.c24_l Circle(arc_centercenter s * (-3.89 * RIGHT 6.54 * UP),radius24/2*s, **self.key_lines_config)self.c12_r Circle(arc_centercenter s * ( 2.11 * RIGHT 6.23 * UP),radius12/2*s, **self.key_lines_config)self.c12_l Circle(arc_centercenter s * (-2.11 * RIGHT 6.23 * UP),radius12/2*s, **self.key_lines_config)self.c8_u Circle(arc_centercenter s * 14.89 * UP, radius8/2*s, **self.key_lines_config)self.c8_01 Circle(arc_centercenter s * (8.82 * RIGHT 6.23 * UP),radius8/2*s, **self.key_lines_config)self.c8_02 Circle(arc_centercenter s * (3.61 * RIGHT 12.23 * UP),radius8/2*s, **self.key_lines_config)self.c8_03 Circle(arc_centercenter s * (-0.46 * RIGHT 15.69 * UP),radius8/2*s, **self.key_lines_config)self.key_lines VGroup(self.c1, self.c5_r, self.c5_l,self.c8_d, self.c13,self.c8_r, self.c8_l,self.c3_r, self.c3_l,self.c24_r, self.c24_l,self.c12_r, self.c12_l,self.c8_u,self.c8_01,self.c8_02, self.c8_03,)self.key_lines_center VGroup(* [Dot(c.get_center(), stroke_colorself.key_lines_config[stroke_color],radiusself.key_lines_config[stroke_width]/100) for c in self.key_lines])return selfdef set_outline(self):s self.scalecenter self.coord_center# kp_list [[7.41, 2.49, 0], [4.81, -1.72, 0], [1.85, -2.22, 0], [-1.85, -2.22, 0], [-4.81, 1.72, 0], [-8.1, 5.91, 0],# [-6.22, 10.6, 0], [-1.74, 11.29, 0], [1.74, 11.29, 0], [6.22, 10.6, 0], [6.95, 9.77, 0], [-0.37, 11.87, 0], [3.42, 16.22, 0]]kp_list [[6.95, 9.77, 0], [6.22, 10.6, 0], [1.74, 11.29, 0], [-1.74, 11.29, 0], [-6.22, 10.6, 0], [-8.1, 5.91, 0],[-4.81, -1.72, 0], [-1.85, -2.22, 0], [1.85, -2.22, 0], [4.81, -1.72, 0], [7.41, 2.49, 0], [-0.35, 11.69, 0], [3.5, 16.23, 0]]self.key_angles np.array([10.62, 69, -51.5, 69, 49.77, 40.52, 73.94, -54.97, 73.94, 23.77, -131.51, 96.09, -96.09]) * DEGREESself.key_radius np.array([12/2, 8/2, 8/2, 8/2, 12/2, 24/2, 5/2, 8/2, 5/2, 24/2, 8/2]) * sself.key_points np.array(kp_list) * s centern len(kp_list)self.outline_by_arcs VGroup_(step_sizeself.step_size)for i in range(n-2):p1, p2 self.key_points[i], self.key_points[(i1) % (n-2)]arc_i ArcBetweenPoints(p1, p2, angleself.key_angles[i], radiusself.key_radius[i], stroke_colorself.logo_color, stroke_widthself.logo_stroke)self.outline_by_arcs.add(arc_i)arc_1 ArcBetweenPoints(self.key_points[-2], self.key_points[-1], angleself.key_angles[-2], radiusself.key_radius[-2], stroke_colorself.logo_color, stroke_widthself.logo_stroke)arc_2 ArcBetweenPoints(self.key_points[-2], self.key_points[-1], angleself.key_angles[-1], radiusself.key_radius[-1], stroke_colorself.logo_color, stroke_widthself.logo_stroke)self.outline_by_arcs.add(arc_1, arc_2)return selfdef set_logo_shape(self):s self.scalecenter self.coord_centerself.outline_by_arcs.get_all_outline_points()self.shape_1 self.outline_by_arcs.get_shape(centercenter s * (-3.89 * RIGHT 6.54 * UP), fill_colorself.logo_color, fill_opacity1, stroke_colorself.logo_color, stroke_widthself.logo_stroke)self.shape_2 self.outline_by_arcs.get_shape(centercenter s * (1.52 * RIGHT 14.05 * UP), fill_colorself.logo_color, fill_opacity1, stroke_colorself.logo_color, stroke_widthself.logo_stroke)# shape_1.set_fill(self.logo_color, 1).set_stroke(self.logo_color, self.logo_stroke, 1)# shape_2.set_fill(self.logo_color, 1).set_stroke(self.logo_color, self.logo_stroke, 1)self.add(self.shape_1, self.shape_2)return self# from my_projects.others.BooleanOperationsOnPolygons import PolygonIntersection, PolygonUnion, PolygonSubtraction
#
# class PolygonBooleanTest(Scene):
# def construct(self):
# pol1 RegularPolygon(9).scale(2).shift(LEFT)
# pol2 RegularPolygon(9).scale(2).shift(RIGHT)
# start time.perf_counter()
# boolpol PolygonSubtraction(
# PolygonUnion(pol1, pol2), PolygonIntersection(pol1, pol2)
# ).set_stroke(colorYELLOW, width0).set_fill(colorYELLOW, opacity0.5)
# end time.perf_counter()
# print(end - start)
# self.add(pol1, pol2, boolpol)
#
#
# pol1 RegularPolygon(16).scale(2)
# pol2 Circle().stretch(1.2, 1).stretch(0.8, 0)
# pol3 RegularPolygon(5).scale(2).shift(LEFT*0.9)
# pol4 RegularPolygon(3).stretch(3, 1).shift(LEFT)
# pol5 Ellipse().scale(0.6).shift(LEFT).stretch(2, 0)
# #start time.perf_counter()
# boolpol PolygonSubtraction(
# PolygonUnion(
# PolygonIntersection(
# PolygonSubtraction(
# pol1, pol2), pol3), pol4), pol5) \
# .set_stroke(colorYELLOW, width0).set_fill(colorYELLOW, opacity0.5)
# #end time.perf_counter()
# #print(end - start)#0.49910769999999993
# self.add(pol1, pol2, pol3, pol4, pol5, boolpol)
#
#class Compass(VGroup):CONFIG {stroke_color: GREY_E,fill_color: WHITE,stroke_width: 2,leg_length: 3,leg_width: 0.12,r: 0.2,depth_test: True,}def __init__(self, span2.5, **kwargs):VGroup.__init__(self, **kwargs)self.span spanself.create_compass()# def create_compass_old(self):## s, l, r self.span, self.leg_length, self.r# theta np.arcsin(s/2/l)# arc Arc(start_angle-PI/2 theta, angleTAU-theta*2, radiusr, stroke_colorself.stroke_color, stroke_widthself.stroke_width*4)# dot Dot(colorself.stroke_color).set_height(self.stroke_width*8/100)# leg_01 Line(arc.get_center(), arc.get_center() complex_to_R3(l * np.exp(1j * (-PI/2-theta))), stroke_colorself.stroke_color, stroke_widthself.stroke_width)# leg_02 Line(arc.get_center(), arc.get_center() complex_to_R3(l * np.exp(1j * (-PI/2theta))), stroke_colorself.stroke_color, stroke_widthself.stroke_width * 1)# leg_11 Line(arc.get_center(), arc.get_center() complex_to_R3((l - r * 0.8) * np.exp(1j * (-PI/2-theta))), stroke_colorself.stroke_color, stroke_widthself.stroke_width * 4)# leg_12 Line(arc.get_center(), arc.get_center() complex_to_R3((l - r * 0.8) * np.exp(1j * (-PI/2theta))), stroke_colorself.stroke_color, stroke_widthself.stroke_width * 4)# pen_point Dot(colorself.stroke_color).set_height(self.stroke_width * 1/125).move_to(leg_02.get_end())# leg_1, leg_2 VGroup(leg_01, leg_11), VGroup(leg_02, leg_12, pen_point)# head Line(UP * r, UP * (r r * 1), stroke_colorself.stroke_color, stroke_widthself.stroke_width * 4)## self.add(arc, dot, head, leg_1, leg_2)# self.move_to(ORIGIN)## return selfdef create_compass(self):s, l, r, w self.span, self.leg_length, self.r, self.leg_widthself.theta np.arcsin(s/2/l)self.c Circle(radiusr, fill_colorself.fill_color, fill_opacity1, stroke_colorself.stroke_color, stroke_widthself.stroke_width*5)c2 Circle(radiusrself.stroke_width*5/100/2, fill_opacity0, stroke_colorself.fill_color, stroke_widthself.stroke_width)self.leg_1 Polygon(ORIGIN, l * RIGHT, (l-w*np.sqrt(3)) * RIGHT w * DOWN, w * DOWN,stroke_width0, stroke_colorself.fill_color, fill_colorself.stroke_color,fill_opacity1).rotate(-PI/2-self.theta, about_pointself.c.get_center())self.leg_2 Polygon(ORIGIN, l * RIGHT, (l-w*np.sqrt(3)) * RIGHT w * UP, w * UP,stroke_width0, stroke_colorself.fill_color, fill_colorself.stroke_color,fill_opacity1).rotate(-PI/2self.theta, about_pointself.c.get_center())# self.leg_1, self.leg_2 VGroup(leg_01, leg_11), VGroup(leg_02, leg_12, pen_point)h Line(UP * r, UP * (r r * 1.8), stroke_colorself.stroke_color, stroke_widthself.stroke_width*6)self.head VGroup(h, self.c, c2)self.add(self.leg_1, self.leg_2, self.head)self.move_to(ORIGIN)return selfdef get_niddle_tip(self):return self.leg_1.get_vertices()[1]def get_pen_tip(self):return self.leg_2.get_vertices()[1]def move_niddle_tip_to(self, pos):self.shift(pos-self.get_niddle_tip())return selfdef rotate_about_niddle_tip(self, anglePI/2):self.rotate(angleangle, about_pointself.get_niddle_tip())def get_span(self):# return self.span 如果进行了缩放而self.span没变会有问题return get_norm(self.get_pen_tip() - self.get_niddle_tip())def set_span(self, s):self.span sl, r, w self.leg_length, self.r, self.leg_widththeta_new, theta_old np.arcsin(s/2/l), self.thetasign np.sign(get_angle(R3_to_complex(self.leg_2.get_vertices()[1] - self.leg_2.get_vertices()[0])) - get_angle(R3_to_complex(self.leg_1.get_vertices()[1] - self.leg_1.get_vertices()[0])))rotate_angle 2 * (theta_new - theta_old) * signself.leg_2.rotate(rotate_angle, about_pointself.c.get_center())self.thetatheta_newself.head.rotate(rotate_angle/2, about_pointself.c.get_center())self.rotate_about_niddle_tip(-rotate_angle/2)return selfdef set_compass(self, center, pen_tip):self.move_niddle_tip_to(center)self.set_span(get_norm(pen_tip - center))self.rotate_about_niddle_tip(np.angle(R3_to_complex(pen_tip - center)) - np.angle(R3_to_complex(self.get_pen_tip() - center)))return selfdef set_compass_to_draw_arc(self, arc):return self.set_compass(arc.arc_center, arc.get_start())def reverse_tip(self):return self.flip(axisself.head[0].get_end() - self.head[0].get_start(), about_pointself.c.get_center())class DrawingScene(Scene):CONFIG {compass_config:{stroke_color: GREY_E,fill_color: WHITE,stroke_width: 2,leg_length: 3,leg_width: 0.12,r: 0.2,depth_test: True,},ruler_config:{width: 10,height: 0.8,stroke_width: 8,stroke_color: GREY_E,stroke_opacity: 0.4,fill_color: WHITE,fill_opacity: 0.5,},dot_config:{radius: 0.06,color: GREY_E,},line_config:{stroke_color: GREY_E,stroke_width: 2.5,},brace_config:{fill_color: GREY_E,buff:0.025,},text_config:{size: 0.6 * 5, # 5 times than the actual size and the sacle downfont: Cambria Math,color: GREY_E,},add_ruler: False,}def setup(self):self.cp Compass(**self.compass_config)self.ruler VGroup(Rectangle(**self.ruler_config).set_height(self.ruler_config[height] - self.ruler_config[stroke_width]/2/100, stretchTrue)\.round_corners(self.ruler_config[height]/8),Rectangle(**self.ruler_config).set_opacity(0))self.dot Dot(**self.dot_config)self.cp.move_to(UP * 10)if self.add_ruler:self.ruler.move_to(DOWN * 10)self.add(self.ruler)self.add(self.cp)self.temp_points []def construct(self):self.add(self.cp)self.play(self.cp.move_niddle_tip_to, ORIGIN, run_time1)self.wait(0.3)self.set_span(3.6, run_time1, rate_funcsmooth)self.wait(0.5)self.set_compass(DL * 0.5, UR * 0.5, run_time1, rate_functhere_and_back)arc Arc(colorGREY_E)self.set_compass_to_draw_arc(arc)self.draw_arc_by_compass(arc)self.wait()def set_span(self, s, run_time1, rate_funcsmooth):s_old self.cp.get_span()n int(run_time * self.camera.frame_rate)dt 1/self.camera.frame_ratet_series np.linspace(1, n, n)/n# s_series s_old rate_func(t_series) * (s - s_old)s_series [s_old rate_func(t_series[i]) * (s - s_old) for i in range(n)]for i in range(n):self.cp.set_span(s_series[i])self.wait(dt)def set_compass_direction(self, start, end, run_time1, rate_funcsmooth):vect end - starta np.angle(R3_to_complex(vect))c_old, p_old self.cp.get_niddle_tip(), self.cp.get_pen_tip()a_old np.angle(R3_to_complex(p_old - c_old))n int(run_time * self.camera.frame_rate)dt 1/self.camera.frame_ratet_series np.linspace(1, n, n)/nc_series [c_old rate_func(t_series[i]) * (start - c_old) for i in range(n)]delta_a (a - a_old)/nfor i in range(n):self.bring_to_front(self.cp)self.cp.move_niddle_tip_to(c_series[i])self.cp.rotate_about_niddle_tip(delta_a)self.wait(dt)def set_compass(self, center, pen_tip, run_time1, rate_funcsmooth, emphasize_dotFalse):if emphasize_dot:run_time - 0.15c_old, p_old self.cp.get_niddle_tip(), self.cp.get_pen_tip()n int(run_time * self.camera.frame_rate)dt 1/self.camera.frame_ratet_series np.linspace(1, n, n)/n# s_series s_old rate_func(t_series) * (s - s_old)c_series [c_old rate_func(t_series[i]) * (center - c_old) for i in range(n)]p_series [p_old rate_func(t_series[i]) * (pen_tip - p_old) for i in range(n)]for i in range(n):self.bring_to_front(self.cp)self.cp.set_compass(c_series[i], p_series[i])self.wait(dt)if emphasize_dot:self.emphasize_dot([center, pen_tip], run_time0.15)def set_compass_(self, center, pen_tip, adjust_angle0, run_time1, rate_funcsmooth, emphasize_dotFalse):vect center - pen_tipa np.angle(R3_to_complex(vect)) adjust_angles get_norm(vect)c_old, p_old, s_old self.cp.get_niddle_tip(), self.cp.get_pen_tip(), self.cp.get_span()a_old np.angle(R3_to_complex(p_old - c_old))if emphasize_dot:run_time - 0.15n int(run_time * self.camera.frame_rate)dt 1/self.camera.frame_ratet_series np.linspace(1, n, n)/nc_series [c_old rate_func(t_series[i]) * (center - c_old) for i in range(n)]delta_a (a - a_old)/ns_series [s_old rate_func(t_series[i]) * (s - s_old) for i in range(n)]for i in range(n):self.bring_to_front(self.cp)self.cp.move_niddle_tip_to(c_series[i])self.cp.rotate_about_niddle_tip(delta_a)self.cp.set_span(s_series[i])self.wait(dt)if emphasize_dot:self.emphasize_dot([center, pen_tip], run_time0.15)def set_compass_to_draw_arc(self, arc, **kwargs):self.set_compass(arc.arc_center, arc.get_start(), **kwargs)def set_compass_to_draw_arc_(self, arc, **kwargs):self.set_compass_(arc.arc_center, arc.get_start(), **kwargs)def draw_arc_by_compass(self, arc, is_preparedTrue, run_time1, rate_funcsmooth, reverseFalse, add_centerFalse, **kwargs):self.bring_to_front(self.cp)if not is_prepared: self.set_compass_to_draw_arc(arc, run_time0.5)theta arc.angle if not reverse else -1 * arc.angleself.play(Rotating(self.cp, angletheta, about_pointself.cp.get_niddle_tip()), ShowCreation(arc), rate_funcrate_func, run_timerun_time)if add_center:d Dot(self.cp.get_niddle_tip(), **self.dot_config).scale(0.5)self.temp_points.append(d)self.add(d)def emphasize_dot(self, pos, add_dotFalse, size1.2, run_time0.2, **kwargs):if type(pos) list:d VGroup(*[Dot(pos[i], radiussize/2, colorGREY_C, fill_opacity0.25).scale(0.25) for i in range(len(pos))])else:d Dot(pos, radiussize/2, colorGREY_C, fill_opacity0.25).scale(0.25)self.add(d)if type(pos) list:self.play(d[0].scale, 4, d[1].scale, 4, rate_funclinear, run_timerun_time)else:self.play(d.scale, 4, rate_funclinear, run_timerun_time)self.remove(d)if add_dot:if type(pos) list:dot VGroup(*[Dot(pos[i],**kwargs) for i in range(len(pos))])else:dot Dot(pos, **kwargs)self.add(dot)return dotdef set_ruler(self, pos1, pos2, run_time1, rate_funcsmooth):p1, p2 self.ruler[-1].get_vertices()[1], self.ruler[-1].get_vertices()[0]c12 (p1 p2) / 2center (pos1 pos2)/2self.bring_to_front(self.ruler)self.play(self.ruler.shift, center - c12, run_timerun_time/2, rate_funcrate_func)self.play(Rotating(self.ruler, anglenp.angle(R3_to_complex(pos2 - pos1)) - np.angle(R3_to_complex(p2 - p1)), about_pointcenter), run_timerun_time/2, rate_funcrate_func)def draw_line(self, pos1, pos2, is_preparedTrue, run_time1.2, rate_funcsmooth, pre_time0.8):if not is_prepared: self.set_ruler(pos1, pos2, run_timepre_time)self.dot.move_to(pos1)self.emphasize_dot(pos1, run_time0.15)self.add(self.dot)l Line(pos1, pos2, **self.line_config)self.play(ShowCreation(l), self.dot.move_to, pos2, run_timerun_time-0.3, rate_funcrate_func)self.emphasize_dot(pos2, run_time0.15)self.remove(self.dot)return ldef draw_line_(self, l, is_preparedTrue, run_time1.2, rate_funcsmooth):pos1, pos2 l.get_start(), l.get_end()if not is_prepared: self.set_ruler(pos1, pos2, run_time0.5)self.dot.move_to(pos1)self.emphasize_dot(pos1, run_time0.15)self.add(self.dot)# l Line(pos1, pos2, **self.line_config)self.play(ShowCreation(l), self.dot.move_to, pos2, run_timerun_time-0.3, rate_funcrate_func)self.emphasize_dot(pos2, run_time0.15)self.remove(self.dot)return ldef put_aside_ruler(self, directionDOWN, run_time0.5):self.bring_to_front(self.ruler)self.play(self.ruler.move_to, direction * 15, run_timerun_time)def put_aside_compass(self, directionDOWN, run_time0.5):self.bring_to_front(self.cp)self.play(self.cp.move_to, direction * 15, run_timerun_time)def get_length_label(self, p1, p2, text, reverse_labelFalse, add_bgFalse, bg_colorWHITE):l Line(p1, p2)b Brace(l, directioncomplex_to_R3(np.exp(1j * (l.get_angle()PI/2 * (1 -2 * float(reverse_label))))), **self.brace_config)t Text(text, **self.text_config).scale(0.2)if add_bg:bg SurroundingRectangle(t, fill_colorbg_color, fill_opacity0.6, stroke_opacity0).set_height(t.get_height() 0.05, stretchTrue).set_width(t.get_width() 0.05, stretchTrue)b.put_at_tip(bg, buff0.0)b.put_at_tip(t, buff0.05)return b, bg, telse:b.put_at_tip(t, buff0.05)return b, tdef set_compass_and_show_span(self, p1, p2, run_time1, show_span_time[0.4, 0.3, 0.9, 0.4], text, reverse_labelFalse, add_bgTrue, **kwargs):self.set_compass(p1, p2, run_timerun_time, **kwargs)bt self.get_length_label(p1, p2, texttext, reverse_labelreverse_label, add_bgadd_bg)b, t bt[0], bt[-1]st show_span_timeself.play(ShowCreation(b), run_timest[0])if add_bg:self.add(bt[1])self.play(FadeIn(t), run_timest[1])else:self.play(FadeIn(t), run_timest[1])self.wait(st[2])self.play(FadeOut(VGroup(*bt)), run_timest[3])return btdef set_compass_and_show_span_(self, p1, p2, run_time1, show_span_time[0.4, 0.3, 0.9, 0.4], text, reverse_labelFalse, add_bgTrue, **kwargs):self.set_compass_(p1, p2, run_timerun_time, **kwargs)bt self.get_length_label(p1, p2, texttext, reverse_labelreverse_label)b, t bt[0], bt[-1]st show_span_timeself.play(ShowCreation(b), run_timest[0])if add_bg:self.add(bt[1])self.play(FadeIn(t), run_timest[1])else:self.play(FadeIn(t), run_timest[1])self.wait(st[2])self.play(FadeOut(VGroup(*bt)), run_timest[3])return btdef highlight_on(self, *mobjects, to_frontTrue, stroke_config{color: #66CCFF, width: 4}, run_time1, **kwargs):self.highlight VGroup(*mobjects)self.play(self.highlight.set_stroke, stroke_config, run_timerun_time, **kwargs)if to_front:self.bring_to_front(self.highlight)self.bring_to_front(self.cp, self.ruler)def highlight_off(self, *mobjects):passdef show_arc_info(self, arc, time_list[0.5, 0.2, 0.3]):c, r, s, a, ps, pe arc.arc_center, arc.radius, arc.start_angle, arc.angle, arc.get_start(), arc.get_end()d_center Dot(c, radius0.08, colorPINK)r1, r2 DashedLine(c, ps, stroke_width3.5, stroke_colorPINK), DashedLine(c, pe , stroke_width3.5, stroke_colorPINK)arc_new Arc(arc_centerc, radiusr, start_angles, anglea, stroke_width8, stroke_colorRED)self.play(ShowCreation(arc_new), run_timetime_list[0])self.play(FadeIn(arc_new), run_timetime_list[1])self.play(ShowCreation(r1), ShowCreation(r2), run_timetime_list[2])class Test_01(Scene):def construct(self):logo Apple_logo()kl logo.key_linesol logo.outline_by_arcsself.play(ShowCreation(kl), run_time6)self.wait(0.25)# self.play(ShowCreation(ol), run_time4)# self.wait(0.8)self.play(DrawBorderThenFill(logo.shape_1, stroke_widthlogo.logo_stroke), run_time3)self.play(DrawBorderThenFill(logo.shape_2, stroke_widthlogo.logo_stroke), run_time1.6)self.wait(0.2)self.play(Uncreate(kl), run_time1.5)self.wait(2)class Test_compass(Scene):def construct(self):coord NumberPlane(axis_config{stroke_color: GREY_D}, background_line_style{stroke_color: BLUE_C},)self.add(coord)cp Compass(stroke_colorPINK)c Circle(radiuscp.get_span())self.add(cp)self.wait()self.play(cp.move_niddle_tip_to, ORIGIN, run_time1)self.wait()self.bring_to_front(cp)self.play(Rotating(cp, about_pointcp.get_niddle_tip()), ShowCreation(c), rate_funcsmooth, run_time1.5)self.bring_to_front(cp)c1 Circle(stroke_colorGREY_E)# self.play(cp.set_span, 1, run_time1)# cp.set_span(1)# self.wait()# self.play(Rotating(cp, about_pointcp.get_niddle_tip()), ShowCreation(c1), rate_funcsmooth, run_time1.5)self.bring_to_front(cp)# self.play(cp.set_compass, DL * 2, UR * 2, run_time1.5)cp.set_compass(DL * 2, UR * 2)self.wait(2)class Test_1(DrawingScene):def construct(self):s 0.5# axis Axes(x_range[-30, 30, 1], y_range[-20, 20, 1], axis_config{stroke_color: GREY_D, stroke_width: 2.5, stroke_opacity: 1},).scale(s)# logo Apple_logo(create_shapeFalse, coord_centerORIGIN, scales*2)# self.add(axis, logo.c1)c Circle(colorBLACK)c1 Circle(colorBLACK)c2 Circle(colorBLACK)self.add(c, c1, c2)self.wait()self.play(ApplyMethod(c.shift, RIGHT * 4, run_time1),ApplyMethod(c1.shift, RIGHT * 4, run_time2),ApplyMethod(c2.shift, RIGHT * 4, run_time4))class Step_0(DrawingScene):画出基本的直角坐标系作为辅助def construct(self):s 0.5# coord NumberPlane(x_range[-15, 15, 1], y_range[-15, 15, 1], axis_config{stroke_color: GREY_D}, background_line_style{stroke_color: BLUE_C},).scale(s)# logo Apple_logo(create_shapeFalse, coord_centerORIGIN, scales)self.cp.move_to(UP * 10)# self.add(coord)self.wait()self.play(FadeIn(self.ruler))l1 self.draw_line(LEFT * 4.5, RIGHT * 4.5, is_preparedFalse)self.put_aside_ruler()self.wait()arc_1 Arc(arc_centerLEFT * 2, radius3, start_angle-PI/3, angle2*PI/3, **self.line_config)arc_2 Arc(arc_centerRIGHT * 2, radius3, start_angle2 * PI/3, angle2*PI/3, **self.line_config)self.play(self.cp.move_to, ORIGIN)self.wait(0.2)self.set_compass_to_draw_arc(arc_1, emphasize_dotTrue)self.draw_arc_by_compass(arc_1)self.wait(0.1)self.set_compass_to_draw_arc_(arc_2, adjust_anglePI, emphasize_dotTrue)self.draw_arc_by_compass(arc_2)self.wait(0.2)self.put_aside_compass()self.set_ruler(UP, DOWN)l2 self.draw_line(UP * 3, DOWN * 3)self.put_aside_ruler(directionLEFT)self.wait(0.6)self.play(FadeOut(arc_1), FadeOut(arc_2), l1.scale, 2, l2.scale, 2, run_time1.2)self.wait(0.8)c1 Circle(radius1*s, **self.line_config)# c2_l Circle(arc_center6*s*LEFT, radius5*s, **self.line_config)# c2_r Arc(arc_center6*s*RIGHT, radius5*s, start_anglePI, angle-TAU, **self.line_config)self.set_compass_to_draw_arc(c1, run_time1.2)self.wait(0.12)self.draw_arc_by_compass(c1)self.wait(0.2)arcs VGroup(*[Arc(arc_centeri*s*RIGHT, radius1*s, start_angle-PI/6, anglePI/3, **self.line_config) for i in range(1, 7)])for i in range(6):self.set_compass_to_draw_arc(arcs[i], run_time0.32, emphasize_dotFalse)self.draw_arc_by_compass(arcs[i], run_time0.5)self.wait(0.6)axis Axes(x_range[-15, 15, 1], y_range[-10, 10, 1], axis_config{stroke_color: GREY_D, stroke_width: 2.5}, ).scale(s)dot Dot(colorGREY_E, radius0.06)self.play(FadeIn(axis), FadeIn(dot), FadeOut(l1), FadeOut(l2), FadeOut(self.cp), FadeOut(arcs))self.wait(2)class Step_1(DrawingScene):画出...def construct(self):s 0.5axis Axes(x_range[-30, 30, 1], y_range[-20, 20, 1], axis_config{stroke_color: GREY_D, stroke_width: 2.5, stroke_opacity: 1},).scale(s)logo Apple_logo(create_shapeFalse, coord_centerORIGIN, scales*2)dot_config {color: GREY_E, radius: 0.06}d1 Dot(**dot_config)self.add(axis, logo.c1, d1)self.wait()d5_l, d5_r Dot(logo.c5_l.get_center(), **dot_config), Dot(logo.c5_r.get_center(), **dot_config)# self.set_compass_to_draw_arc(logo.c5_l, emphasize_dotTrue)self.set_compass_and_show_span(logo.c5_l.get_center(), logo.c5_l.get_start(), reverse_labelTrue, textr5)self.wait(0.1)self.draw_arc_by_compass(logo.c5_l)self.cp.reverse_tip()logo.c5_r.flip()self.wait(0.15)self.add(d5_l)self.set_compass_to_draw_arc(logo.c5_r, emphasize_dotTrue)# self.set_compass_to_draw_arc_(logo.c5_r, emphasize_dotTrue)self.draw_arc_by_compass(logo.c5_r, reverseTrue)self.wait(0.1)self.add(d5_r)self.put_aside_compass(directionUP)self.wait(0.4)self.play(VGroup(*self.mobjects).scale, 0.6, {about_point: ORIGIN}, run_time1.2)self.play(VGroup(*self.mobjects).shift, UP * 2, run_time1.2)# s_vg VGroup(axis, logo.c5_l, logo.c5_r, logo.c1)# s_vg2 logo.key_lines.remove(logo.c5_l, logo.c5_r, logo.c1)# self.play(s_vg.scale, 0.5, {about_point: ORIGIN}, run_time1.2)# s_vg2.scale(0.5, about_pointORIGIN)# self.wait(0.4)# self.set_compass_(logo.c8_d.get_center(), logo.c8_d.get_start(), emphasize_dotTrue)# # self.set_compass_to_draw_arc(logo.c8_d, emphasize_dotTrue)# self.draw_arc_by_compass(logo.c8_d)self.wait(2)class Step_11(DrawingScene):CONFIG {compass_config:{stroke_color: GREY_E,fill_color: WHITE,stroke_width: 2,leg_length: 4,leg_width: 0.12,r: 0.2,depth_test: True,},add_ruler: True,}def construct(self):s 0.5 * 0.6axis Axes(x_range[-30, 30, 1], y_range[-25, 25, 1], axis_config{stroke_color: GREY_D, stroke_width: 2.5, stroke_opacity: 1},).scale(s).shift(UP * 2)logo Apple_logo(create_shapeFalse, coord_centerUP * 2, scales*2)dot_config {color: GREY_E, radius: 0.03}d1 Dot(logo.c1.get_center(), **dot_config)d5_l, d5_r Dot(logo.c5_l.get_center(), **dot_config), Dot(logo.c5_r.get_center(), **dot_config)self.add(axis, logo.c1, logo.c5_l, logo.c5_r, d1, d5_l, d5_r)self.wait()self.cp.move_to(DOWN * 10)self.cp.rotate_about_niddle_tip(PI)arc_13_l Arc(arc_centerlogo.c5_l.get_center(), radius13 * s, start_angle3*PI/2, anglePI/4, **self.line_config)arc_13_r Arc(arc_centerlogo.c5_r.get_center(), radius13 * s, start_angle3*PI/2-PI/4, anglePI/4 PI/2, **self.line_config)self.highlight_on(logo.c5_l, logo.c5_r)self.wait(0.15)self.set_compass_and_show_span(logo.c5_l.get_center(), logo.c5_l.get_center() (5 8) * s * LEFT, reverse_labelTrue, textr5813, run_time1.4)self.wait(0.4)self.set_compass_to_draw_arc_(arc_13_l, adjust_anglePI, rate_funclinear, run_time0.6)self.draw_arc_by_compass(arc_13_l, rate_funclinear, run_time0.3)self.wait(0.12)self.set_compass_(logo.c5_r.get_center(), logo.c5_r.get_center() (5 8) * s * LEFT, adjust_anglePI, emphasize_dotTrue, run_time1.4)self.wait(0.2)self.set_compass_to_draw_arc_(arc_13_r, adjust_angle-PI, rate_funclinear, run_time0.6)self.draw_arc_by_compass(arc_13_r, rate_funclinear, run_time0.9)self.wait(0.6)self.set_compass_and_show_span(axis.c2p(11, 0), axis.c2p(19, 0), reverse_labelTrue, textr8, run_time1.2)self.wait(0.15)self.set_compass_to_draw_arc_(logo.c8_d.scale(0.995), adjust_angle-PI, run_time1.)self.draw_arc_by_compass(logo.c8_d, run_time1.2)d8_d Dot(logo.c8_d.get_center(), **dot_config)self.add(d8_d)self.wait(0.2)self.put_aside_compass(UP * 0.5, run_time1.)self.play(FadeOut(arc_13_l), FadeOut(arc_13_r))self.remove(self.cp)self.wait(0.4)self.play(logo.c5_r.set_stroke, {color: GREY_E, width: 2.5}, logo.c5_l.set_stroke, {color: GREY_E, width: 2.5}, run_time0.6)self.wait(0.2)self.play(VGroup(*self.mobjects).shift, DOWN * 4, run_time1.25)self.wait(2)class Step_12(DrawingScene):def construct(self):s 0.5 * 0.6axis Axes(x_range[-30, 30, 1], y_range[-30, 30, 1], axis_config{stroke_color: GREY_D, stroke_width: 2.5, stroke_opacity: 1},).scale(s).shift(DOWN * 2)logo Apple_logo(create_shapeFalse, coord_centerDOWN * 2, scales*2)dot_config {color: GREY_E, radius: 0.03}d1 Dot(logo.c1.get_center(), **dot_config)d5_l, d5_r Dot(logo.c5_l.get_center(), **dot_config), Dot(logo.c5_r.get_center(), **dot_config)self.add(axis, logo.c1, logo.c5_l, logo.c5_r, logo.c8_d.scale(0.995), d1, d5_l, d5_r)self.set_compass_and_show_span(axis.c2p(0, 13), axis.c2p(0,0), emphasize_dotTrue, reverse_labelTrue, textr13, run_time2)self.wait(0.6)logo.c13.rotate(-PI/2)self.set_compass_to_draw_arc(logo.c13, emphasize_dotTrue)self.wait(0.2)d13 Dot(logo.c13.get_center(), **dot_config)a_13 Arc(arc_centerlogo.c8_d.get_center() UP * 8 * s, start_anglePI/2 PI/20, radius13 * s, angle-PI/10, **self.line_config)self.cp.reverse_tip()self.set_compass_to_draw_arc(a_13, run_time0.25)self.draw_arc_by_compass(a_13, run_time0.5)self.add(d13)self.wait(0.25)self.put_aside_compass(RIGHT * 0.8, run_time1.2)self.wait(0.6)self.play(VGroup(*self.mobjects).scale, 0.8, {about_point: axis.c2p(0,0)}, run_time1.2)self.wait(2)class Step_2(DrawingScene):画出辅助正方形CONFIG {compass_config:{stroke_color: GREY_E,fill_color: WHITE,stroke_width: 2,leg_length: 4,leg_width: 0.12,r: 0.2,depth_test: True,},}def construct(self):s 0.5 * 0.6 * 0.8axis Axes(x_range[-40, 40, 1], y_range[-36, 36, 1], axis_config{stroke_color: GREY_D, stroke_width: 2.5, stroke_opacity: 1},).scale(s).shift(DOWN * 2)logo Apple_logo(create_shapeFalse, coord_centerDOWN * 2, scales*2)dot_config {color: GREY_E, radius: 0.03}d1 Dot(logo.c1.get_center(), **dot_config)d5_l, d5_r Dot(logo.c5_l.get_center(), **dot_config), Dot(logo.c5_r.get_center(), **dot_config)a_13 Arc(arc_centerlogo.c8_d.get_center() UP * 8 * s, start_anglePI/2 PI/30, radius13 * s, angle-PI/15, **self.line_config)d13 Dot(logo.c13.get_center(), **dot_config)self.add(axis, logo.c1, logo.c5_l, logo.c5_r, logo.c8_d.scale(0.995), a_13, d1, d5_l, d5_r, d13)self.wait()self.play(FadeIn(self.ruler))self.wait(0.2)dl, dr logo.c5_l.get_center() * 8/13 logo.c8_d.get_center() * 5/13, logo.c5_r.get_center() * 8/13 logo.c8_d.get_center() * 5/13self.set_ruler(dl, dr)self.emphasize_dot([dl, dr], run_time0.2)# l Line(dl LEFT * 4.5, dr RIGHT *4.5, **self.line_config)self.wait(0.5)l self.draw_line(dl LEFT * 3.6, dr RIGHT * 3.6, run_time1.25)self.put_aside_ruler(DOWN * 0.4)self.wait(0.1)dm (dldr)/2self.set_compass(d13.get_center(), dm, emphasize_dotTrue, run_time1.5)self.wait(0.2)a_13_r Arc(arc_centerdm, radiusself.cp.get_span(), start_angle10 * DEGREES, angle-20 * DEGREES, **self.line_config)a_13_l Arc(arc_centerdm, radiusself.cp.get_span(), start_angle190 * DEGREES, angle-20 * DEGREES, **self.line_config)# a_13_u Arc(arc_centerd13.get_center(), radiusself.cp.get_span(), start_angle100 * DEGREES, angle20 * DEGREES, **self.line_config)l_square get_norm(d13.get_center()-dm)circle Circle(arc_centerd13.get_center(), radiusl_square * np.sqrt(2), **self.line_config).rotate(-PI/4)self.cp.reverse_tip()self.set_compass_to_draw_arc_(a_13_l, adjust_anglePI, run_time0.64)self.draw_arc_by_compass(a_13_l, run_time0.12, rate_funclinear)self.set_compass_to_draw_arc_(a_13_r, adjust_anglePI, run_time0.96, rate_funclinear)self.draw_arc_by_compass(a_13_r, run_time0.12, rate_funclinear)self.wait(0.25)self.cp.reverse_tip()self.set_compass_to_draw_arc(circle, run_time1.2, emphasize_dotTrue)self.wait(0.15)self.draw_arc_by_compass(circle, run_time1.6)self.wait(0.5)self.set_compass(dm l_square * LEFT, dm l_square * RIGHT, emphasize_dotTrue)self.wait(0.2)self.cp.reverse_tip()arc_r Arc(arc_centerdm l_square * RIGHT, radiusl_square * 2, start_angle100 * DEGREES, angle-20 * DEGREES, **self.line_config)arc_l Arc(arc_centerdm l_square * LEFT, radiusl_square * 2, start_angle80 * DEGREES, angle20 * DEGREES, **self.line_config)# self.set_compass_to_draw_arc_(arc_r, adjust_anglePI, run_time0.6, rate_funclinear)self.play(Rotating(self.cp, angle-80 * DEGREES, about_pointself.cp.get_niddle_tip(), rate_funclinear), run_time0.6)self.draw_arc_by_compass(arc_r, run_time0.15, rate_funclinear)self.wait(0.2)# self.set_compass_(dm l_square * RIGHT, dm l_square * LEFT, emphasize_dotTrue)self.play(Rotating(self.cp, angle100 * DEGREES, about_pointself.cp.get_niddle_tip()), run_time0.8)self.emphasize_dot([self.cp.get_niddle_tip(), self.cp.get_pen_tip()], run_time0.15)self.wait(0.2)self.cp.reverse_tip()self.set_compass_to_draw_arc_(arc_l, adjust_anglePI, run_time0.6, rate_funclinear)self.draw_arc_by_compass(arc_l, run_time0.15, rate_funclinear)self.wait(0.2)self.put_aside_compass(LEFT)self.wait(0.6)dots [dm l_square * RIGHT, dm l_square * (RIGHT 2 * UP), dm l_square * (LEFT 2 * UP), dm l_square * LEFT]# self.set_ruler(dots[0], dots[1])l_r self.draw_line(dots[0], dots[1], is_preparedFalse, pre_time0.75)self.wait(0.2)l_u self.draw_line(dots[1], dots[2], is_preparedFalse, pre_time0.75)self.wait(0.2)l_l self.draw_line(dots[3], dots[2], is_preparedFalse, pre_time0.75)l_d Line(dots[3], dots[0],**self.line_config)self.wait(0.18)self.put_aside_ruler(LEFT * 0.7)self.wait(0.9)self.play(Transform(l, l_d, run_time0.9),FadeOut(a_13_r, run_time0.6),# FadeOut(a_13, run_time0.8),FadeOut(a_13_l, run_time0.8),FadeOut(arc_r, run_time1.),FadeOut(arc_l, run_time1.2),FadeOut(circle, run_time1.4))self.wait(0.75)self.play(VGroup(*self.mobjects).scale, 0.8, {about_point: axis.c2p(0,0)})self.wait(2)class Step_3(DrawingScene):CONFIG {add_ruler: True,}def construct(self):s 0.5 * 0.6 * 0.8 * 0.8axis Axes(x_range[-40, 40, 1], y_range[-36, 36, 1], axis_config{stroke_color: GREY_D, stroke_width: 2.5, stroke_opacity: 1},).scale(s).shift(DOWN * 2)logo Apple_logo(create_shapeFalse, coord_centerDOWN * 2, scales*2)dot_config {color: GREY_E, radius: 0.03}d1 Dot(logo.c1.get_center(), **dot_config)d5_l, d5_r Dot(logo.c5_l.get_center(), **dot_config), Dot(logo.c5_r.get_center(), **dot_config)a_13 Arc(arc_centerlogo.c8_d.get_center() UP * 8 * s, start_anglePI/2 PI/30, radius13 * s, angle-PI/15, **self.line_config)d13 Dot(logo.c13.get_center(), **dot_config)dl, dr logo.c5_l.get_center() * 8/13 logo.c8_d.get_center() * 5/13, logo.c5_r.get_center() * 8/13 logo.c8_d.get_center() * 5/13dm (dldr)/2l_square get_norm(d13.get_center()-dm)dots [dm l_square * RIGHT, dm l_square * (RIGHT 2 * UP), dm l_square * (LEFT 2 * UP), dm l_square * LEFT]square Polygon(*dots, **self.line_config)before VGroup(axis, logo.c1, logo.c5_l, logo.c5_r, logo.c8_d.scale(0.995), a_13, d1, d5_l, d5_r, d13, square)self.add(before)self.wait()dots square.get_vertices()r1 l_square * 0.7### left part ###a_1 Arc(arc_centerdots[2], radiusr1, start_anglePI/3, angle-2 * PI/3, **self.line_config)a_2 Arc(arc_center(dots[1] dots[2])/2, radiusr1, start_angle2 * PI/3, angle2 * PI/3, **self.line_config)self.cp.flip(axisRIGHT)self.set_compass_to_draw_arc(a_1)self.draw_arc_by_compass(a_1)self.wait(0.15)self.cp.reverse_tip()self.set_compass_to_draw_arc_(a_2, adjust_anglePI)self.draw_arc_by_compass(a_2)self.put_aside_compass(RIGHT * 0.8, run_time0.64)pm (dots[2] (dots[1] dots[2])/2)/2pu, pd pm 10 * s * UP, pm 10 * s * DOWNl self.draw_line(pu, pd, is_preparedFalse, pre_time0.72)self.wait(0.18)self.put_aside_ruler(LEFT * 0.65)logo.c8_l.rotate(PI/2)self.set_compass_and_show_span_(axis.c2p(0,0), axis.c2p(0,8), run_time1.4, emphasize_dotTrue, adjust_anglePI, textr8, reverse_labelTrue, add_bgTrue)self.wait(0.5)self.set_compass_to_draw_arc_(logo.c8_l, adjust_anglePI, emphasize_dotTrue)self.wait(0.2)self.draw_arc_by_compass(logo.c8_l, run_time1.25, add_centerTrue)self.wait(0.2)self.put_aside_compass(LEFT * 0.64)self.wait(0.6)### right part ### 同理直接copy吧a_3 Arc(arc_center(dots[1] dots[2])/2, radiusr1, start_anglePI/3, angle-2 * PI/3, **self.line_config)a_4 Arc(arc_centerdots[1], radiusr1, start_angle2 * PI/3, angle2 * PI/3, **self.line_config)d8_r Dot(logo.c8_r.get_center(), **dot_config)pm_r (dots[1] (dots[1] dots[2])/2)/2pu_r, pd_r pm_r 10 * s * UP, pm_r 10 * s * DOWNlogo.c8_r.rotate(PI/2)l02 Line(pu_r, pd_r, **self.line_config)right_part VGroup(a_3, a_4, l02, logo.c8_r)right_part_ right_part.copy().set_stroke(opacity0.32).shift(l_square * LEFT)self.add(right_part_)self.play(right_part_.shift, l_square * RIGHT)self.wait(0.2)self.play(ShowCreation(a_3), run_time0.8)self.play(ShowCreation(a_4), run_time0.8)self.play(ShowCreation(l02), run_time0.8)self.play(ShowCreation(logo.c8_r), FadeIn(d8_r))self.remove(right_part_)self.wait()self.play(FadeOut(a_4, run_time0.6), FadeOut(l02, run_time0.7), FadeOut(a_3, run_time0.8),FadeOut(a_2, run_time0.9), FadeOut(l, run_time1.), FadeOut(a_1, run_time1.1),)self.wait(0.8)self.play(VGroup(*self.mobjects).scale, 1.25, {about_point: axis.c2p(0,0)})self.wait(2)class Step_4(DrawingScene):CONFIG {add_ruler: True,}def construct(self):s 0.5 * 0.6 * 0.8axis Axes(x_range[-45, 45, 1], y_range[-36, 36, 1], axis_config{stroke_color: GREY_D, stroke_width: 2.5, stroke_opacity: 1},).scale(s).shift(DOWN * 2)logo Apple_logo(create_shapeFalse, coord_centerDOWN * 2, scales*2)dot_config {color: GREY_E, radius: 0.03}d1 Dot(logo.c1.get_center(), **dot_config)d5_l, d5_r Dot(logo.c5_l.get_center(), **dot_config), Dot(logo.c5_r.get_center(), **dot_config)参考文献
1.https://www.tiobe.com/tiobe-index 2.https://baike.baidu.com/item/Python/407313?fraladdin 3.https://docs.manim.community/en/stable/installation.html 4.https://docs.manim.org.cn/