Mobject
The defined background rectangle functions for
Mobject in mobject.py
- def add_background_rectangle(self, color=BLACK, opacity=0.75, **kwargs)
- def add_background_rectangle_to_submobjects(self, **kwargs)
- def add_background_rectangle_to_family_members_with_points(self, **kwargs)
def add_background_rectangle(self, color=BLACK, opacity=0.75, **kwargs)
add_background_rectangle is used to add a background rectangle to a
Mobject according to the specified parameters.
def add_background_rectangle_to_submobjects(self, **kwargs)
add_background_rectangle_to_submobjects is used to add a background rectangle to each submobjects of the
Mobject according to the specified parameters.
def add_background_rectangle_to_family_members_with_points(self, **kwargs)
add_background_rectangle is used to add a background rectangle to family_members_with_points of a
Mobject according to the specified parameters.
Example
Code
# folder/file: tut/manim_mobject_func_backgroundrectangle_001a.py
from manimlib.scene.scene import Scene
from manimlib.mobject.geometry import Rectangle, Square, Circle, Line,RoundedRectangle, Dot
from manimlib.animation.creation import ShowCreation
from manimlib.mobject.svg.tex_mobject import TexMobject, TextMobject
from manimlib.animation.fading import FadeOut
from manimlib.animation.creation import Write
from manimlib.animation.transform import ApplyMethod, ApplyFunction
class manim_mobject_func_backgroundrectangle_001a(Scene):
def construct(self):
linex=Line([2,2,0],[1,1,0],color="#88FF00")
polya= RoundedRectangle(width=2,height=2,corner_radius=0.5,stroke_width=0,fill_color="#FFFF00",fill_opacity=1)
polyb = Rectangle(width=2.5,height=1.5,stroke_width=15,color="#88FF00",fill_color="#FFFF00",fill_opacity=1)
polyc= Square(side_length=2,stroke_width=20,fill_color="#FF8800",fill_opacity=1).move_to([-3,-2,0])
polyd= Circle(arc_center=(-2,0.75,0),color="#888888")
polya.add(Rectangle(width=2,height=2,color="#77DDCC").move_to(polya))
polya.add(Rectangle(width=1,height=2.5,color="#77DDCC").move_to(polya))
polya.add(TextMobject("A").move_to([2,0,0]))
polye = RoundedRectangle(width=1.25,height=3.75,corner_radius=0.5,color="#888888",fill_color="#333333",fill_opacity=1).move_to([-0.625,-1.125,0])
polyf= Rectangle(width=1,height=2,color="#888888").move_to([-2.5,-2,0])
polyg= Rectangle(width=1,height=2,color="#888888").move_to([2,-2,0])
polyb.add(polye)
self.play(ShowCreation(polyb),run_time=2)
self.wait()
self.play(ShowCreation(polyc),ShowCreation(polyf),run_time=2)
self.wait()
polyb.add(polyg)
self.wait()
self.play(ShowCreation(polya.move_to(polyd)),ShowCreation(polyd),run_time=2)
self.wait()
self.add(TextMobject("B").move_to([0,0,0]))
self.add(TextMobject("C").move_to(polyc))
self.add(TextMobject("E").move_to(polye))
textg=TextMobject("G").move_to([1,-2,0])
polyb.add(textg)
self.add(linex)
self.add(Rectangle(width=14.22,height=8))
self.wait()
text=TexMobject("polya.add\_background\_rectangle(color=\"\#FF8833\")").move_to([0,3,0])
self.play(Write(text),ApplyFunction(lambda mob:mob.add_background_rectangle(color="#FF8833"),polya),run_time=3)
self.wait()
self.play(FadeOut(text),run_time=2)
text=TexMobject("polya.add\_background\_rectangle\_to\_submobjects\cr(color=\"\#FF8833\", opacity=0.25)").move_to([0,3,0])
self.play(Write(text),ApplyFunction(lambda mob:mob.add_background_rectangle_to_submobjects(color="#FF8833", opacity=0.25),polyb),run_time=3)
self.wait()
self.play(FadeOut(text),run_time=2)
text=TexMobject("polya.add\_background\_rectangle\_to\_family\_members\cr\_with\_points(color=\"\#FF8833\")").move_to([0,3,0])
self.play(Write(text),ApplyFunction(lambda mob:mob.add_background_rectangle_to_family_members_with_points(color="#668833"),polyb),run_time=5)
self.wait()
self.play(FadeOut(text),run_time=2)
Output