Skip to content

Commit b1f8f6b

Browse files
committed
Move Scene.freeze_background() and Camera.extract_mobject_family_members()
1 parent aef7eec commit b1f8f6b

File tree

4 files changed

+49
-38
lines changed

4 files changed

+49
-38
lines changed

manim/camera/camera.py

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from ..utils.simple_functions import fdiv
2929
from ..utils.space_ops import angle_of_vector
3030
from ..utils.space_ops import get_norm
31+
from ..utils.family import extract_mobject_family_members
3132

3233

3334
class Camera(object):
@@ -363,33 +364,6 @@ def set_frame_to_background(self, background):
363364

364365
####
365366

366-
# TODO, it's weird that this is part of camera.
367-
# Clearly it should live elsewhere.
368-
def extract_mobject_family_members(self, mobjects, only_those_with_points=False):
369-
"""Returns a list of the types of mobjects and
370-
their family members present.
371-
372-
Parameters
373-
----------
374-
mobjects : Mobject
375-
The Mobjects currently in the Scene
376-
only_those_with_points : bool, optional
377-
Whether or not to only do this for
378-
those mobjects that have points. By default False
379-
380-
Returns
381-
-------
382-
list
383-
list of the mobjects and family members.
384-
"""
385-
if only_those_with_points:
386-
method = Mobject.family_members_with_points
387-
else:
388-
method = Mobject.get_family
389-
if self.use_z_index:
390-
mobjects = sorted(mobjects, key=lambda m: m.z_index)
391-
return remove_list_redundancies(list(it.chain(*[method(m) for m in mobjects])))
392-
393367
def get_mobjects_to_display(
394368
self, mobjects, include_submobjects=True, excluded_mobjects=None
395369
):
@@ -411,11 +385,13 @@ def get_mobjects_to_display(
411385
list of mobjects
412386
"""
413387
if include_submobjects:
414-
mobjects = self.extract_mobject_family_members(
415-
mobjects, only_those_with_points=True
388+
mobjects = extract_mobject_family_members(
389+
mobjects, use_z_index=self.use_z_index, only_those_with_points=True
416390
)
417391
if excluded_mobjects:
418-
all_excluded = self.extract_mobject_family_members(excluded_mobjects)
392+
all_excluded = extract_mobject_family_members(
393+
excluded_mobjects, use_z_index=self.use_z_index
394+
)
419395
mobjects = list_difference_update(mobjects, all_excluded)
420396
return mobjects
421397

manim/scene/scene.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from ..scene.scene_file_writer import SceneFileWriter
2424
from ..utils.iterables import list_update
2525
from ..utils.hashing import get_hash_from_play_call, get_hash_from_wait_call
26+
from ..utils.family import extract_mobject_family_members
2627
from ..renderer.cairo_renderer import CairoRenderer
2728

2829

@@ -168,11 +169,6 @@ def get_attrs(self, *keys):
168169
"""
169170
return [getattr(self, key) for key in keys]
170171

171-
def freeze_background(self):
172-
self.renderer.update_frame()
173-
self.camera = Camera(self.renderer.get_frame())
174-
self.clear()
175-
176172
###
177173

178174
def update_mobjects(self, dt):
@@ -248,7 +244,9 @@ def get_mobject_family_members(self):
248244
list
249245
List of mobject family members.
250246
"""
251-
return self.camera.extract_mobject_family_members(self.mobjects)
247+
return extract_mobject_family_members(
248+
self.mobjects, use_z_index=self.renderer.camera.use_z_index
249+
)
252250

253251
def add(self, *mobjects):
254252
"""
@@ -337,7 +335,9 @@ def restructure_mobjects(
337335
The Scene mobject with restructured Mobjects.
338336
"""
339337
if extract_families:
340-
to_remove = self.camera.extract_mobject_family_members(to_remove)
338+
to_remove = extract_mobject_family_members(
339+
to_remove, use_z_index=self.renderer.camera.use_z_index
340+
)
341341
_list = getattr(self, mobject_list_name)
342342
new_list = self.get_restructured_mobject_list(_list, to_remove)
343343
setattr(self, mobject_list_name, new_list)

manim/scene/vector_space_scene.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ def lock_in_faded_grid(self, dimness=0.7, axes_dimness=0.5):
109109
axes.set_color(WHITE)
110110
axes.fade(axes_dimness)
111111
self.add(axes)
112-
self.freeze_background()
112+
113+
self.renderer.update_frame()
114+
self.renderer.camera = Camera(self.renderer.get_frame())
115+
self.clear()
113116

114117
def get_vector(self, numerical_vector, **kwargs):
115118
"""

manim/utils/family.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import itertools as it
2+
3+
from ..mobject.mobject import Mobject
4+
from ..utils.iterables import remove_list_redundancies
5+
6+
7+
def extract_mobject_family_members(
8+
mobjects, use_z_index=False, only_those_with_points=False
9+
):
10+
"""Returns a list of the types of mobjects and
11+
their family members present.
12+
13+
Parameters
14+
----------
15+
mobjects : Mobject
16+
The Mobjects currently in the Scene
17+
only_those_with_points : bool, optional
18+
Whether or not to only do this for
19+
those mobjects that have points. By default False
20+
21+
Returns
22+
-------
23+
list
24+
list of the mobjects and family members.
25+
"""
26+
if only_those_with_points:
27+
method = Mobject.family_members_with_points
28+
else:
29+
method = Mobject.get_family
30+
if use_z_index:
31+
mobjects = sorted(mobjects, key=lambda m: m.z_index)
32+
return remove_list_redundancies(list(it.chain(*[method(m) for m in mobjects])))

0 commit comments

Comments
 (0)