Manim文档及源码笔记-CE文档-示例库4特殊摄像机设置
参考原文:
Manim Community Edition
Example Gallery
前言
笔记随想:
暂未发现官方中文版,自己实践代码的同时,顺便做翻译加深理解~
除了给出原文档中的展现效果及源码,我把实践代码过程的笔记也分享出来,另外最后设计出一些技能训练的内容,强化学校效果。行文格式:示例-标号及名称
展现效果
操作拆解
源码直击
代码实践
技能训练
本示例库包含一系列最佳实践代码片段及其相应的视频/图像输出,展示了整个库的不同功能。这些都是在麻省理工学院的许可下,所以请随意复制并粘贴到您的项目中。享受这Manim的味道!
更新【new】:
- 8月23日
-
- “笔记随想”前后标注了“前言”与“正文”;
-
- 本系列暂告段落,把“上一节”、“下一节”升级为系列目录,放到了文尾;
- 后续更新备忘:文中“【建设中】”的内容;欢迎朋友们催更~
正文
特殊摄像机设置,Special Camera Settings
示例1:FollowingGraphCamera
展现效果1
FollowingGraphCamera
操作拆解1
上一节我们对建立坐标系越来越熟练了,本案例开始做一些比较酷的事情;
焦点/视角/镜头/参照物落在动点上;
- 做轴和曲线,create the axes and the curve
- 做曲线上的动点,create dots based on the graph
- 留意调用play时参数camera的技巧
源码直击1
%%manim -v WARNING -qm FollowingGraphCamera
from manim import *
class FollowingGraphCamera(MovingCameraScene):
def construct(self):
self.camera.frame.save_state()
# create the axes and the curve
ax = Axes(x_range=[-1, 10], y_range=[-1, 10])
graph = ax.plot(lambda x: np.sin(x), color=BLUE, x_range=[0, 3 * PI])
# create dots based on the graph
moving_dot = Dot(ax.i2gp(graph.t_min, graph), color=ORANGE)
dot_1 = Dot(ax.i2gp(graph.t_min, graph))
dot_2 = Dot(ax.i2gp(graph.t_max, graph))
self.add(ax, graph, dot_1, dot_2, moving_dot)
self.play(self.camera.frame.animate.scale(0.5).move_to(moving_dot))
def update_curve(mob):
mob.move_to(moving_dot.get_center())
self.camera.frame.add_updater(update_curve)
self.play(MoveAlongPath(moving_dot, graph, rate_func=linear))
self.camera.frame.remove_updater(update_curve)
self.play(Restore(self.camera.frame))
参考:moving_camera_scene,MovingCameraScene,MoveAlongPath,Restore,plot(),add_updater()
代码实践1
技能训练1
单独整理到此【建设中】
示例2:MovingZoomedSceneAround
展现效果2
MovingZoomedSceneAround