Shape Matcher
The defined shape matcher
VMobject in shape_matchers.py
- Class SurroundingRectangle(Rectangle)
- Class BackgroundRectangle(SurroundingRectangle)
- Class Cross(VGroup)
- Class Underline(Line)
Class SurroundingRectangle(Rectangle)
SurroundingRectangle is used to generate a surrounding rectangle with respect to specified
VMobject for given parameters.
Example
Code
# folder/file: tut/manim_mobject_surroundingrectangle_001a.py
from manimlib.scene.scene import Scene
from manimlib.mobject.shape_matchers import SurroundingRectangle
from manimlib.mobject.geometry import VMobject, Square, Triangle
from manimlib.mobject.svg.tex_mobject import TexMobject
class manim_mobject_surroundingrectangle_001a(Scene):
def construct(self):
triangle=Triangle(fill_color="#FF3300",fill_opacity=1)
trianglebg=SurroundingRectangle(triangle,fill_opacity=1)
self.add(VMobject.add(trianglebg,triangle).move_to([-3,3,0])).wait(2)
triangle=Triangle(fill_color="#333300",fill_opacity=1)
trianglebg=SurroundingRectangle(triangle,fill_opacity=0.5).shift([1,0,0])
self.add(VMobject.add(triangle,trianglebg).move_to([3,3,0])).wait(2)
self.add(SurroundingRectangle(VMobject.add(triangle,trianglebg)).move_to([-3,-3,0])).wait(2)
text1= TexMobject("TEXT").move_to([3,-1.5,0])
text1bg= SurroundingRectangle(text1,color="#FF3300",fill_color="#FF3333", fill_opacity=.5)
self.add(VMobject.add(text1bg,text1).move_to([3,-3,0])).wait(2)
Output
Class BackgroundRectangle(SurroundingRectangle)
BackgroundRectangle is used to generate a background rectangle with respect to specified
VMobject for given parameters.
Example
Code
# folder/file: tut/manim_mobject_backgroundrectangle_001a.py
from manimlib.scene.scene import Scene
from manimlib.mobject.shape_matchers import BackgroundRectangle
from manimlib.mobject.geometry import VMobject, Square, Triangle
from manimlib.mobject.svg.tex_mobject import TexMobject
class manim_mobject_backgroundrectangle_001a(Scene):
def construct(self):
triangle=Triangle(fill_color="#FF3300",fill_opacity=1)
trianglebg=BackgroundRectangle(triangle,fill_color="#FFFFFF",fill_opacity=1)
self.add(VMobject.add(trianglebg,triangle).move_to([-3,3,0])).wait(2)
triangle=Triangle(fill_color="#333300",fill_opacity=1)
trianglebg=BackgroundRectangle(triangle,fill_color="#FFFFFF",fill_opacity=0.5).shift([1,0,0])
self.add(VMobject.add(triangle,trianglebg).move_to([3,3,0])).wait(2)
self.add(BackgroundRectangle(VMobject.add(triangle,trianglebg),fill_color="#FFFFFF").move_to([-3,-3,0])).wait(2)
text1= TexMobject("TEXT")
text1bg= BackgroundRectangle(text1,color="#FFFF00",fill_color="#FFFFFF", fill_opacity=.5)
self.add(VMobject.add(text1bg,text1).move_to([3,-3,0])).wait(2)
Output
Class Cross(VGroup)
Cross is used to generate a cross with respect to specified
VMobject for given parameters.
Example
Code
# folder/file: tut/manim_mobject_cross_001a.py
from manimlib.scene.scene import Scene
from manimlib.mobject.shape_matchers import Cross
from manimlib.mobject.geometry import VMobject, Square, Triangle
from manimlib.mobject.svg.tex_mobject import TexMobject
class manim_mobject_cross_001a(Scene):
def construct(self):
triangle=Triangle(fill_color="#FF3300",fill_opacity=1)
trianglebg=Cross(triangle,fill_color="#FFFFFF",fill_opacity=1)
self.add(VMobject.add(trianglebg,triangle).move_to([-3,3,0])).wait(2)
triangle=Triangle(fill_color="#333300",fill_opacity=1)
trianglebg=Cross(triangle,fill_color="#FFFFFF",fill_opacity=0.5).shift([1,0,0])
self.add(VMobject.add(triangle,trianglebg).move_to([3,3,0])).wait(2)
self.add(Cross(VMobject.add(triangle,trianglebg),fill_color="#FFFFFF").move_to([-3,-3,0])).wait(2)
text1= TexMobject("TEXT")
text1bg= Cross(text1,color="#FFFF00",fill_color="#FFFFFF", fill_opacity=.5)
self.add(VMobject.add(text1bg,text1).move_to([3,-3,0])).wait(2)
Output
Class Underline(Line)
Underline is used to generate an underline with respect to specified
VMobject for given parameters.
Example
Code
# folder/file: tut/manim_mobject_underline_001a.py
from manimlib.scene.scene import Scene
from manimlib.mobject.shape_matchers import Underline
from manimlib.mobject.geometry import VMobject, Square, Triangle
from manimlib.mobject.svg.tex_mobject import TexMobject
class manim_mobject_underline_001a(Scene):
def construct(self):
triangle=Triangle(fill_color="#FF3300",fill_opacity=1)
trianglebg=Underline(triangle,fill_color="#FFFFFF",fill_opacity=1)
self.add(VMobject.add(trianglebg,triangle).move_to([-3,3,0])).wait(2)
triangle=Triangle(fill_color="#333300",fill_opacity=1)
trianglebg=Underline(triangle,fill_color="#FFFFFF",fill_opacity=0.5).shift([1,0,0])
self.add(VMobject.add(triangle,trianglebg).move_to([3,3,0])).wait(2)
self.add(Underline(VMobject.add(triangle,trianglebg),fill_color="#FFFFFF").move_to([-3,-3,0])).wait(2)
text1= TexMobject("TEXT")
text1bg= Underline(text1,color="#FFFF00",fill_color="#FFFFFF", fill_opacity=.5)
self.add(VMobject.add(text1bg,text1).move_to([3,-3,0])).wait(2)
Output