Skip to content

Commit 304fd4d

Browse files
committed
Move Scene.add_frame()
1 parent a7fb0ee commit 304fd4d

File tree

2 files changed

+38
-36
lines changed

2 files changed

+38
-36
lines changed

manim/renderer/cairo_renderer.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@ def get_frame(self):
6262
"""
6363
return np.array(self.camera.pixel_array)
6464

65+
def add_frame(self, frame, num_frames=1):
66+
"""
67+
Adds a frame to the video_file_stream
68+
69+
Parameters
70+
----------
71+
frame : numpy.ndarray
72+
The frame to add, as a pixel array.
73+
num_frames: int
74+
The number of times to add frame.
75+
"""
76+
dt = 1 / self.camera.frame_rate
77+
self.scene.increment_time(num_frames * dt)
78+
if file_writer_config["skip_animations"]:
79+
return
80+
for _ in range(num_frames):
81+
self.file_writer.write_frame(frame)
82+
6583
def update_skipping_status(self):
6684
"""
6785
This method is used internally to check if the current

manim/scene/scene.py

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ def progress_through_animations(self):
757757
for t in self.get_animation_time_progression(self.animations):
758758
self.update_animation_to_time(t)
759759
self.renderer.update_frame(self.moving_mobjects, self.static_image)
760-
self.add_frame(self.renderer.get_frame())
760+
self.renderer.add_frame(self.renderer.get_frame())
761761

762762
def update_animation_to_time(self, t):
763763
"""
@@ -805,6 +805,21 @@ def play(self, *args, **kwargs):
805805
self.cached_play(*args, **kwargs)
806806
self.num_plays += 1
807807

808+
def revert_to_original_skipping_status(self):
809+
"""
810+
Forces the scene to go back to its original skipping status,
811+
by setting skip_animations to whatever it reads
812+
from original_skipping_status.
813+
814+
Returns
815+
-------
816+
Scene
817+
The Scene, with the original skipping status.
818+
"""
819+
if hasattr(self, "original_skipping_status"):
820+
file_writer_config["skip_animations"] = self.original_skipping_status
821+
return self
822+
808823
def cached_play(self, *args, **kwargs):
809824
self.revert_to_original_skipping_status()
810825
self.renderer.update_skipping_status()
@@ -888,7 +903,7 @@ def wait_internal(self, duration=DEFAULT_WAIT_TIME, stop_condition=None):
888903
for t in time_progression:
889904
self.update_animation_to_time(t)
890905
self.renderer.update_frame()
891-
self.add_frame(self.renderer.get_frame())
906+
self.renderer.add_frame(self.renderer.get_frame())
892907
if stop_condition is not None and stop_condition():
893908
time_progression.close()
894909
break
@@ -898,7 +913,9 @@ def wait_internal(self, duration=DEFAULT_WAIT_TIME, stop_condition=None):
898913
else:
899914
self.renderer.update_frame()
900915
dt = 1 / self.camera.frame_rate
901-
self.add_frame(self.renderer.get_frame(), num_frames=int(duration / dt))
916+
self.renderer.add_frame(
917+
self.renderer.get_frame(), num_frames=int(duration / dt)
918+
)
902919
return self
903920

904921
def clean_up_animations(self, *animations):
@@ -971,39 +988,6 @@ def wait_until(self, stop_condition, max_time=60):
971988
"""
972989
self.wait(max_time, stop_condition=stop_condition)
973990

974-
def revert_to_original_skipping_status(self):
975-
"""
976-
Forces the scene to go back to its original skipping status,
977-
by setting skip_animations to whatever it reads
978-
from original_skipping_status.
979-
980-
Returns
981-
-------
982-
Scene
983-
The Scene, with the original skipping status.
984-
"""
985-
if hasattr(self, "original_skipping_status"):
986-
file_writer_config["skip_animations"] = self.original_skipping_status
987-
return self
988-
989-
def add_frame(self, frame, num_frames=1):
990-
"""
991-
Adds a frame to the video_file_stream
992-
993-
Parameters
994-
----------
995-
frame : numpy.ndarray
996-
The frame to add, as a pixel array.
997-
num_frames: int
998-
The number of times to add frame.
999-
"""
1000-
dt = 1 / self.camera.frame_rate
1001-
self.increment_time(num_frames * dt)
1002-
if file_writer_config["skip_animations"]:
1003-
return
1004-
for _ in range(num_frames):
1005-
self.file_writer.write_frame(frame)
1006-
1007991
def add_sound(self, sound_file, time_offset=0, gain=None, **kwargs):
1008992
"""
1009993
This method is used to add a sound to the animation.

0 commit comments

Comments
 (0)