mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
set_variables_as_attrs method on Scene
This commit is contained in:
parent
065a34fb51
commit
666fe16e8c
1 changed files with 12 additions and 9 deletions
|
@ -75,20 +75,23 @@ class Scene(object):
|
|||
self.name = name
|
||||
return self
|
||||
|
||||
def update_shared_locals(self, *keys):
|
||||
def set_variables_as_attrs(self, *objects, **newly_named_objects):
|
||||
"""
|
||||
Often in constructing a scene, it's nice to refer to
|
||||
what was a local variable from a previous subroutine,
|
||||
so a dict of shared_locals is recorded, and it can be updated
|
||||
by passing in the objects directly.
|
||||
This method is slightly hacky, making it a little easier
|
||||
for certain methods (typically subroutines of construct)
|
||||
to share local variables.
|
||||
"""
|
||||
caller_locals = inspect.currentframe().f_back.f_locals
|
||||
self.shared_locals.update(dict([
|
||||
(key, caller_locals[key])
|
||||
for key in keys
|
||||
]))
|
||||
for key, value in caller_locals.items():
|
||||
if value in objects:
|
||||
setattr(self, key, value)
|
||||
for key, value in newly_named_objects.items():
|
||||
setattr(self, key, value)
|
||||
return self
|
||||
|
||||
def get_attrs(self, *keys):
|
||||
return [getattr(self, key) for key in keys]
|
||||
|
||||
### Only these methods should touch the camera
|
||||
|
||||
def set_camera(self, camera):
|
||||
|
|
Loading…
Add table
Reference in a new issue