Manim v0.17.03相机聚焦动画报错:'Camera'无'frame'属性
问题解决:Manim v0.17.03中相机操作报错AttributeError
错误原因
Manim v0.17.x版本对相机API做了调整,Camera类不再包含frame属性,旧版本中通过camera.frame实现的相机动画逻辑需要改用新的API。
修正后的代码
场景类代码
class CameraFocusing(Scene): def construct(self): s = Square(color=YELLOW).move_to(np.array([-4,0,0])) c = Circle().move_to(np.array([4,0,0])) self.add(s,c) self.wait(3) # 瞬间将相机聚焦到正方形中心 self.camera.frame_center = s.get_center() self.wait(3) # 动画将相机移动到圆形中心(替代原frame.animate.shift逻辑) self.play(self.camera.animate.set_frame_center(c.get_center()), run_time=2) self.wait(2)
主配置代码(去除重复配置项)
if __name__ == "__main__": config.pixel_height = 720 config.pixel_width = 1280 config.frame_height = 7.0 config.frame_width = 7.0 config.frame_center = [-4, 0, 0] config.background_color = BLACK config.save_as_gif = True config.quality = "medium" config.media_height = 7.0 config.media_width = 7.0 scene = CameraFocusing() scene.render()
额外说明
- 如果需要实现自定义偏移的相机动画,也可以直接对
frame_center做属性动画,比如:# 动画将相机向右偏移8个单位 self.play(self.camera.animate.frame_center.shift(8 * RIGHT), run_time=2) - Manim v0.17+中,相机的核心控制属性包括
frame_center(位置)、frame_height(视野高度)、frame_width(视野宽度),直接操作这些属性或通过animate修饰即可实现相机的静态调整与动画效果。
内容的提问来源于stack exchange,提问作者Mukul Sharma
相关产品推荐
相关产品推荐

