Element Management
The Element management functions of
Scene object is to manage the
Mobject objects of
Scene object. The Element management functions are
- def add(self, *mobjects)
- def remove(self, *mobjects)
- def add_mobjects_among(self, values)
- def add_foreground_mobjects(self, *mobjects)
- def add_foreground_mobject(self, mobject)
- def remove_foreground_mobjects(self, *to_remove)
- def remove_foreground_mobject(self, mobject)
- def clear(self)
def add_mobjects_among(self, values)
Add one, more, or all
Mobject object instances in the local symbol table at this code point of available to the casting list of
Scene object. Any
Mobject object instance declared after this calling point is not included. The order of background and foreground arrangement depends on the order of symbolic varibale in the local symbol table. The
add_mobjects_among function can be used to add all mobjects using
locals().values(), to add one or more mobjects using functions like
filter(lambda x: x!=temp,locals().values()), or mapping like
map(locals().get,{"temp"}) etc.
last updated 28Dec2019
Example Scene.add_mobjects_among
Example of Scene.add_mobjects_among
Code Scene.add_mobjects_among
# folder/file: tut/manim_scene_add_among_001a.py
from manimlib.scene.scene import Scene
from manimlib.mobject.geometry import Circle
from manimlib.mobject.geometry import Square
class manim_scene_add_among_001a(Scene):
def construct(self):
temp1=Square(color="#FFFF00")
temp2=Circle(radius=1.2,color="#FF0000",stroke_width=10)
temp3=Circle()
self.add_mobjects_among(map(locals().get,{"temp1","temp2"}))
temp1=Circle(stroke_width=10,radius=2.5)
temp2=Square(color="#FFFFFF",side_length=4)
temp3=Circle(radius=2.2,color="#FF0000",stroke_width=10)
self.add_mobjects_among(filter(lambda x: x!=temp1,locals().values()))
temp1=Square(color="#FFFF00")
temp2=Circle(radius=1.2,color="#FF0000",stroke_width=10)
temp3=Circle()
temp4=Circle(color="#FFFF00",radius=1.75)
temp5=Square(color="#FFFF00",side_length=2.25)
temp6=Square(side_length=5.25)
self.add_mobjects_among(locals().values())
temp7=Square(side_length=7)
print(locals().values())
Output Scene.add_mobjects_among
def add_foreground_mobjects(self, *mobjects)
Add one or more
Mobject objects to both the priority casting list and casting list of
Scene object. The priority casting list is used as an flag indicator to indicate that all
Mobject in the priority casting list at this code point and after should be promoted to the front of the casting list of
Scene object. And similar to
add function,
Mobjects are added to
Scene object from background to foreground in the order with which these
Mobject objects are added.
last updated 28Dec2019
Example Scene.add_foreground_mobjects
Example of Scene.add_foreground_mobjects
Code Scene.add_foreground_mobjects
# folder/file: tut/manim_scene_add_foreground_mobjects_001a.py
from manimlib.scene.scene import Scene
from manimlib.mobject.geometry import Circle
from manimlib.mobject.geometry import Square
class manim_scene_add_foreground_mobjects_001a(Scene):
def construct(self):
temp=Square()
temp1=Circle(stroke_width=10)
temp2=Square(color="#FFFF00",stroke_width=10,side_length=1.8)
temp3=Square(fill_opacity=1)
self.add(temp)
self.add_foreground_mobjects(temp1,temp2)
self.add(temp3)
Output Scene.add_foreground_mobjects
def add_foreground_mobject(self, mobject)
Same function as
add_foreground_mobjects, but add only one
Mobject object to the priority casting list of
Scene object instead of to the casting list.
last updated 28Dec2019
Example Scene.add_foreground_mobject
Example of Scene.add_foreground_mobject.
Code Scene.add_foreground_mobject
# folder/file: tut/manim_scene_add_foreground_mobject_001a.py
from manimlib.scene.scene import Scene
from manimlib.mobject.geometry import Circle
from manimlib.mobject.geometry import Square
class manim_scene_add_foreground_mobject_001a(Scene):
def construct(self):
temp=Square()
temp1=Circle(stroke_width=10)
temp2=Square(color="#FFFF00",stroke_width=10,side_length=1.8)
temp3=Square(fill_opacity=1)
self.add(temp)
self.add_foreground_mobject(temp1)
self.add_foreground_mobject(temp2)
self.add(temp3)
Output Scene.add_foreground_mobject