본문 바로가기

Programming/Manim Lectures

[05-3-D] Polygon series(1/2): Polygon/Triangle/ArrowTip

반응형

In this page, we will learn how to create polygon-like shapes.

The top class is Ploygon, and general polygons can be created using Ploygon, such as Rectangle and Triangle.

 

Polygon class

object > Container > Mobject > VMobject > Polygon
manimlib.mobject.geometry.Polygon(self, *vertices, **kwargs)

Create a polygon using given points.  By default, a polygon with no inner color and blue outline is created.

 

    CONFIG = {
        "color": BLUE,
    }
Parameters: *vertices
    Points to draw polygons. 
    A polygon must be given at least three points. 
    If two are given, a line is created

Parameters: **kwargs
    CONFIG values of Polygon and VMobject/Mobject

    Frequently used variables are:
    - color=BLUE: line color. possible to set with ' ' variable
    - stroke_width=4: line thickness. default is 4 

Ploygon is the top class for creating polygons. Connect the given points to make a polygon.

p=Polygon(UP+LEFT, ORIGIN, DOWN+LEFT, RIGHT)


RegularPolygon class

object > Container > Mobject > VMobject > Polygon > RegularPolygon
manimlib.mobject.geometry.RegularPolygon(self, n=6, **kwargs)

Create a regular polygon. n=6 is the default, in this case we make a regular hexagon. 

If n=3, it is a regular triangle; if n=4, it is a square. 

 

The larger n is, the closer it is to a circle.

 

p = RegularPolygon()

 

    CONFIG = {
        "start_angle": None,
    }
Parameters: n
    Create a regular n-square shape according to n. 
    n=3 is a regular triangle, n=4 is a square

Parameters: **kwargs
    CONFIG values of RegularPolygon ans Polygon/VMobject/Mobject 

    Frequently used variables are:
    - start_angle=None: set starting positon of the RegularPolygon
    - color=BLUE: line color. it's same to set with ' ' variable
    - stroke_width=4: line thickness. default value is 4

Depending on the start_angle, the starting point at which the polygon is drawn can be different. In the figure below, start_angle=0 on the left and start_angle=PI/2 on the right.

 

        left = RegularPolygon()
        right = RegularPolygon(start_angle=PI/2)

The larger the value of n, the closer the circle becomes. 

Below is an animation that gradually increases the n value so that the shape starting from the triangle gradually turns into a circle.

 

    def regulat_test3(self):
        tracker = ValueTracker(3)

        rp = RegularPolygon(3, fill_opacity=1, fill_color=RED)
        num = DecimalNumber(3,num_decimal_places=0).next_to(rp,UP)

        def update_func(mob):
            n = int(tracker.get_value())
            new_mob = RegularPolygon(n, fill_opacity=1, fill_color=RED)
            mob.become(new_mob)
            num.set_value(n)

        self.add(rp, num)
        self.play(
            tracker.set_value, 12,
            UpdateFromFunc(rp,update_func),
            rate_func=linear, run_time=5
        )
        self.wait()

 


Triangle class

object > Container > Mobject > VMobject > Polygon > RegularPolygon > Triangle
manimlib.mobject.geometry.Triangle(self, **kwargs)

Create a triangle.

The Triangle class is when n=3 in Polygon.

 

triangle = Triangle()

 

There is no CONFIG value only for Triangle class.

Parameters: **kwargs
    CONFIG values for RegularPolygon/Polygon/VMobject/Mobject

    Frequently used variables are: 
    -start_angle=None: starting position for the Polygon
    - color=BLUE: line color. it's same effect if you use ' ' variable
    - stroke_width=4: line thickness. default value is 4

ArrowTip class

 object > Container > Mobject > VMobject > Polygon > RegularPolygon > Triangle > ArrowTip
manimlib.mobject.geometry.ArrowTip(self, **kwargs)

Create an arrowhead-shaped triangle.
The triangle created by default is 0.35 in length, and a blue arrowhead-shaped triangle is created.

 

tip = ArrowTip()

 

    CONFIG = {
        "fill_opacity": 1,
        "stroke_width": 0,
        "length": DEFAULT_ARROW_TIP_LENGTH,
        "start_angle": PI,
    }
Parameters: **kwargs
  CONFIG values of ArrowTip and Triangle/RegularPolygon/Polygon/VMobject/Mobject

  Frequently used variables are:
  - fill_opacity=1: Internal color transparency
  - stroke_width=0: Specify the thickness of the outline.
  - lenght=DEFAULT_ARROW_TIP_LENGTH=0.35: arrow's tip length
  - start_angle=PI: starting angle

Next: [05-3-E] Polygon series(2/2): Rectangle/Square/Rounded Rectangle

 

[05-3-E] Polygon series(2/2): Rectangle/Square/Rounded Rectangle

Rectangle class object > Container > Mobject > VMobject > Polygon > Rectangle manimlib.mobject.geometry.Rectangle(self, **kwargs) Create a rectangle. By default, a white rectangle with a width is..

infograph.tistory.com

Go To: [99] Table of Contents

반응형