3D 曲面的明暗由光源位置决定。示例画一个球面,把相机光源从默认位置移到 3*IN(正对屏幕外),再用棋盘格配色看清光照变化。
完整代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| from manim import * import numpy as np class ThreeDLightSourcePosition(ThreeDScene): def construct(self): axes = ThreeDAxes() sphere = Surface( lambda u, v: np.array([ 1.5 * np.cos(u) * np.cos(v), 1.5 * np.cos(u) * np.sin(v), 1.5 * np.sin(u) ]), v_range=[0, TAU], u_range=[-PI / 2, PI / 2], checkerboard_colors=[RED_D, RED_E], resolution=(15, 32) ) self.renderer.camera.light_source.move_to(3*IN) self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES) self.play(*[FadeIn(_o) for _o in [axes, sphere]], run_time=1.0) self.wait(1) self.wait(3.60)
|
演示视频
下载 Python 脚本
要点
self.renderer.camera.light_source.move_to(...) 改的是场景光源,不是对象颜色
Surface 的 checkerboard_colors 用两种颜色交替,便于观察曲面结构
resolution=(u 段数, v 段数) 越大越平滑,渲染也越慢
代码来源:Manim Community 官方 Example Gallery 示例 ThreeDLightSourcePosition(MIT),已在 Manim CE 0.20.1 实跑验证并生成上方视频。
主观感受,仅供参考。本文采用 本文采用 CC BY-NC-SA 4.0 许可 协议,
完整转载请注明来自
数学动画引擎。