Geometry Polygon
The defined geometry
VMobject related to polygon in geometry.py
- Class Polygon(VMobject)
- Class RegularPolygon(Polygon)
- Class Triangle(RegularPolygon)
- Class ArrowTip(Triangle)
- Class Rectangle(Polygon)
- Class Square(Rectangle)
- Class RoundedRectangle(Rectangle)
Class Polygon(VMobject)
Polygon is a general purpose closed continuous line constructor for a 3D point array.
Polygon can be used to generate polygon of any type from a given point set.
Polygon can also be used as a dummy polygon constructor for other defined polygon. Crossed polygon is also accepted.
Example
Code
# folder/file: tut/manim_mobject_polygon_001a.py
from manimlib.scene.scene import Scene
from manimlib.mobject.geometry import Polygon
from manimlib.animation.creation import ShowCreation
class manim_mobject_polygon_001a(Scene):
def construct(self):
poly = Polygon((0,0,0),(1,1,0),(2,-1.2,0),(3,0,0),(2,-1,0),(1,-1,0),stroke_width=15,color="#88FF00",fill_color="#FFFF00",fill_opacity=1)
self.play(ShowCreation(poly),run_time=2)
self.play(ShowCreation(Polygon((-6.5,3,0),(-5,4,0),(-2,-1.2,0))),run_time=2)
self.play(ShowCreation(Polygon((-5.5,3,0),(-4,4,0),stroke_width=50)),run_time=2)
self.play(ShowCreation(Polygon((5.5,3,0),stroke_width=50)),run_time=2)
Output
Class Class RegularPolygon(Polygon)
RegularPolygon is used to generate regular polygon for a given number of sides
Example
Code
# folder/file: tut/manim_mobject_regularpolygon_001a.py
from manimlib.scene.scene import Scene
from manimlib.mobject.geometry import RegularPolygon
from manimlib.animation.creation import ShowCreation
class manim_mobject_regularpolygon_001a(Scene):
def construct(self):
poly = RegularPolygon(stroke_width=15,color="#88FF00",fill_color="#FFFF00",fill_opacity=1)
self.play(ShowCreation(poly.scale(2)),run_time=2)
self.play(ShowCreation(RegularPolygon(1)),run_time=2)
self.play(ShowCreation(RegularPolygon(2)),run_time=2)
self.play(ShowCreation(RegularPolygon(4).scale(1.5)),run_time=2)
Output
Class Triangle(RegularPolygon)
Triangle is used to generate regular triangular shape.
Example
Code
# folder/file: tut/manim_mobject_triangle_001a.py
from manimlib.scene.scene import Scene
from manimlib.mobject.geometry import Triangle
from manimlib.animation.creation import ShowCreation
class manim_mobject_triangle_001a(Scene):
def construct(self):
poly = Triangle(stroke_width=15,color="#88FF00",fill_color="#FFFF00",fill_opacity=1)
self.play(ShowCreation(poly),run_time=2)
self.play(ShowCreation(Triangle().scale(2)),run_time=2)
self.play(ShowCreation(Triangle().scale(0.5)),run_time=2)
self.play(ShowCreation(Triangle(stroke_width=10).scale_about_point(2,(0,0,0))),run_time=2)
Output
Class ArrowTip(Triangle)
ArrowTip is used to generate triangular arrow tip.
Example
Code
# folder/file: tut/manim_mobject_arrowtip_001a.py
from manimlib.scene.scene import Scene
from manimlib.mobject.geometry import ArrowTip
from manimlib.animation.creation import ShowCreation
class manim_mobject_arrowtip_001a(Scene):
def construct(self):
poly = ArrowTip(stroke_width=15,color="#88FF00",fill_color="#FFFF00",fill_opacity=1)
self.play(ShowCreation(ArrowTip(stroke_width=10).scale_about_point(2,(0,0,0))),run_time=2)
self.play(ShowCreation(poly),run_time=2)
self.play(ShowCreation(ArrowTip().shift((2,0,0)).scale(2)),run_time=2)
self.play(ShowCreation(ArrowTip().shift((0,0.5,0))),run_time=2)
Output
Class Rectangle(Polygon)
Rectangle is used to generate rectangular shape for given height and width.
Example
Code
# folder/file: tut/manim_mobject_rectangle_001a.py
from manimlib.scene.scene import Scene
from manimlib.mobject.geometry import Rectangle
from manimlib.animation.creation import ShowCreation
class manim_mobject_rectangle_001a(Scene):
def construct(self):
poly = Rectangle(stroke_width=15,color="#88FF00",fill_color="#FFFF00",fill_opacity=1)
self.play(ShowCreation(poly),run_time=2)
self.play(ShowCreation(Rectangle(width=3.5,height=2,color="#000000")),run_time=2)
self.play(ShowCreation(Rectangle(width=3,height=1,color="#008800")),run_time=2)
self.play(ShowCreation(Rectangle().scale(1.5)),run_time=2)
Output
Class Square(Rectangle)
Square is used to generate a square shape for given
side_length.
Example
Code
# folder/file: tut/manim_mobject_square_001a.py
from manimlib.scene.scene import Scene
from manimlib.mobject.geometry import Square
from manimlib.animation.creation import ShowCreation
class manim_mobject_square_001a(Scene):
def construct(self):
poly = Square(stroke_width=15,color="#88FF00",fill_color="#FFFF00",fill_opacity=1)
self.play(ShowCreation(poly),run_time=2)
self.play(ShowCreation(Square(side_length=1,color="#000000")),run_time=2)
self.play(ShowCreation(Square(side_length=5,color="#008800")),run_time=2)
self.play(ShowCreation(Square().scale(1.5)),run_time=2)
Output
Class RoundedRectangle(Rectangle)
RoundedRectangle is used to generate a rounded rectangular shape with
corner_radius in additional to
width and
height.
Example
Code
# folder/file: tut/manim_mobject_roundedrectangle_001a.py
from manimlib.scene.scene import Scene
from manimlib.mobject.geometry import RoundedRectangle
from manimlib.animation.creation import ShowCreation
class manim_mobject_roundedrectangle_001a(Scene):
def construct(self):
poly = RoundedRectangle(stroke_width=15,color="#88FF00",fill_color="#FFFF00",fill_opacity=1)
self.play(ShowCreation(poly),run_time=2)
self.play(ShowCreation(RoundedRectangle(width=3.5,height=2,corner_radius=1,color="#000000")),run_time=2)
self.play(ShowCreation(RoundedRectangle(width=3,height=0.7,color="#008800")),run_time=1.5)
self.play(ShowCreation(RoundedRectangle().scale(1.5)),run_time=2)
Output