Skip to content

Commit aef7eec

Browse files
committed
Move Scene.update_frame()
1 parent e42c48f commit aef7eec

File tree

2 files changed

+48
-46
lines changed

2 files changed

+48
-46
lines changed

manim/renderer/cairo_renderer.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import numpy as np
2+
from .. import file_writer_config
3+
from ..utils.iterables import list_update
24

35

46
class CairoRenderer:
@@ -7,6 +9,46 @@ def __init__(self, scene, camera, file_writer):
79
self.camera = camera
810
self.file_writer = file_writer
911

12+
def update_frame( # TODO Description in Docstring
13+
self,
14+
mobjects=None,
15+
background=None,
16+
include_submobjects=True,
17+
ignore_skipping=True,
18+
**kwargs,
19+
):
20+
"""Update the frame.
21+
22+
Parameters
23+
----------
24+
mobjects: list, optional
25+
list of mobjects
26+
27+
background: np.ndarray, optional
28+
Pixel Array for Background.
29+
30+
include_submobjects: bool, optional
31+
32+
ignore_skipping : bool, optional
33+
34+
**kwargs
35+
36+
"""
37+
if file_writer_config["skip_animations"] and not ignore_skipping:
38+
return
39+
if mobjects is None:
40+
mobjects = list_update(
41+
self.scene.mobjects,
42+
self.scene.foreground_mobjects,
43+
)
44+
if background is not None:
45+
self.camera.set_frame_to_background(background)
46+
else:
47+
self.camera.reset()
48+
49+
kwargs["include_submobjects"] = include_submobjects
50+
self.camera.capture_mobjects(mobjects, **kwargs)
51+
1052
def get_frame(self):
1153
"""
1254
Gets the current frame as NumPy array.

manim/scene/scene.py

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -168,48 +168,8 @@ def get_attrs(self, *keys):
168168
"""
169169
return [getattr(self, key) for key in keys]
170170

171-
def update_frame( # TODO Description in Docstring
172-
self,
173-
mobjects=None,
174-
background=None,
175-
include_submobjects=True,
176-
ignore_skipping=True,
177-
**kwargs,
178-
):
179-
"""Update the frame.
180-
181-
Parameters
182-
----------
183-
mobjects: list, optional
184-
list of mobjects
185-
186-
background: np.ndarray, optional
187-
Pixel Array for Background.
188-
189-
include_submobjects: bool, optional
190-
191-
ignore_skipping : bool, optional
192-
193-
**kwargs
194-
195-
"""
196-
if file_writer_config["skip_animations"] and not ignore_skipping:
197-
return
198-
if mobjects is None:
199-
mobjects = list_update(
200-
self.mobjects,
201-
self.foreground_mobjects,
202-
)
203-
if background is not None:
204-
self.camera.set_frame_to_background(background)
205-
else:
206-
self.camera.reset()
207-
208-
kwargs["include_submobjects"] = include_submobjects
209-
self.camera.capture_mobjects(mobjects, **kwargs)
210-
211171
def freeze_background(self):
212-
self.update_frame()
172+
self.renderer.update_frame()
213173
self.camera = Camera(self.renderer.get_frame())
214174
self.clear()
215175

@@ -811,7 +771,7 @@ def progress_through_animations(self):
811771
"""
812772
for t in self.get_animation_time_progression(self.animations):
813773
self.update_animation_to_time(t)
814-
self.update_frame(self.moving_mobjects, self.static_image)
774+
self.renderer.update_frame(self.moving_mobjects, self.static_image)
815775
self.add_frame(self.renderer.get_frame())
816776

817777
def update_animation_to_time(self, t):
@@ -919,7 +879,7 @@ def play_internal(self, *args, **kwargs):
919879
# Paint all non-moving objects onto the screen, so they don't
920880
# have to be rendered every frame
921881
self.moving_mobjects = self.get_moving_mobjects(*self.animations)
922-
self.update_frame(excluded_mobjects=self.moving_mobjects)
882+
self.renderer.update_frame(excluded_mobjects=self.moving_mobjects)
923883
self.static_image = self.renderer.get_frame()
924884
self.last_t = 0
925885
self.run_time = self.get_run_time(self.animations)
@@ -941,7 +901,7 @@ def wait_internal(self, duration=DEFAULT_WAIT_TIME, stop_condition=None):
941901
# the same way Scene.play does
942902
for t in time_progression:
943903
self.update_animation_to_time(t)
944-
self.update_frame()
904+
self.renderer.update_frame()
945905
self.add_frame(self.renderer.get_frame())
946906
if stop_condition is not None and stop_condition():
947907
time_progression.close()
@@ -950,7 +910,7 @@ def wait_internal(self, duration=DEFAULT_WAIT_TIME, stop_condition=None):
950910
# Do nothing
951911
return self
952912
else:
953-
self.update_frame()
913+
self.renderer.update_frame()
954914
dt = 1 / self.camera.frame_rate
955915
self.add_frame(self.renderer.get_frame(), num_frames=int(duration / dt))
956916
return self
@@ -1116,7 +1076,7 @@ def show_frame(self):
11161076
Opens the current frame in the Default Image Viewer
11171077
of your system.
11181078
"""
1119-
self.update_frame(ignore_skipping=True)
1079+
self.renderer.update_frame(ignore_skipping=True)
11201080
self.camera.get_image().show()
11211081

11221082

0 commit comments

Comments
 (0)