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
|
self.name = name
|
||||||
return self
|
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
|
This method is slightly hacky, making it a little easier
|
||||||
what was a local variable from a previous subroutine,
|
for certain methods (typically subroutines of construct)
|
||||||
so a dict of shared_locals is recorded, and it can be updated
|
to share local variables.
|
||||||
by passing in the objects directly.
|
|
||||||
"""
|
"""
|
||||||
caller_locals = inspect.currentframe().f_back.f_locals
|
caller_locals = inspect.currentframe().f_back.f_locals
|
||||||
self.shared_locals.update(dict([
|
for key, value in caller_locals.items():
|
||||||
(key, caller_locals[key])
|
if value in objects:
|
||||||
for key in keys
|
setattr(self, key, value)
|
||||||
]))
|
for key, value in newly_named_objects.items():
|
||||||
|
setattr(self, key, value)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def get_attrs(self, *keys):
|
||||||
|
return [getattr(self, key) for key in keys]
|
||||||
|
|
||||||
### Only these methods should touch the camera
|
### Only these methods should touch the camera
|
||||||
|
|
||||||
def set_camera(self, camera):
|
def set_camera(self, camera):
|
||||||
|
|
Loading…
Add table
Reference in a new issue