본문 바로가기

Programming/Manim Lectures

[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 4 and height is 2 is created around the origin.

 

rect = Rectangle()

 

    CONFIG = {
        "color": WHITE,
        "height": 2.0,
        "width": 4.0,
        "mark_paths_closed": True,
        "close_new_points": True,
    }
Parameters: **kwargs
    CONFIG values of Rectangle and Polygon/VMobject/Mobject

    Frequently used variables are:
    - color=WHITE: line color. possible to use ' ' to set the line color
    - height=2.0: height length
    - width=4.0: width length
    - stroke_width=4: line thickness
    - fill_color=None: set color for inner space of rectangle
    - fill_opacity=0.0: set opacity for inner space of rectangle

Square class

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

Create a square.
By default, a white square with a width of 2 and a height of 2 is created around the origin.

 

square = Square()

    CONFIG = {
        "side_length": 2.0,
    }
Parameters: **kwargs
  Square 및 Rectangle/Polygon/VMobject/Mobject 의 CONFIG 값

  주로 사용되는 값은,
  - side_length=2: 정사각형의 한 변의 길이
  - color=WHITE: 선의 색상 지정.  를 지정해도 동일한 효과 
  - stroke_width=4: 선의 두께 지정. 
  - fill_color=None: 객체 내부 색상 지정
  - fill_opacity=0.0: 객체 내부 투명도 지정

RoundedRectangle class

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

Create a rectangle with rounded corners.
By default, a white rectangle is created, width of 2 and height of 1, around the origin.

 

rect = RoundedRectangle()

 

    CONFIG = {
        "corner_radius": 0.5,
    }
Parameters: **kwargs
    CONFIG values of RoundedRectangle and Rectangle/Polygon/VMobject/Mobject

    Frequently used variables are: 
    - corner_radius=0.5: Determines the roundness of the corners. 
                       Value greater than zero. 
                       The greater the roundness, the greater the roundness
    - side_length=2: The length of one side of the square
    - color=WHITE: line color
    - stroke_width=4: line thickness
    - fill_color=None: color for inner space of the rectangle
    - fill_opacity=0.0: transparancy of inner space

 

You can determine the roundness of the corners by adjusting the corner_radius value. 

 

The value should be a value greater than 0, and the larger the value, the greater the roundness.  If the value of corner_radius is greater than the length of one side of the rectangle, the shape becomes strange.


Below is an example of creating a rectangle based on the value of corner_radius.  If the length of the vertical is 1, and corner_radius> 1, you can see that the shape changes strangely.

 

    def round_test(self):
        values = [0.1, 0.5,1,1.5,2]

        def get_rect(val):
            rect = RoundedRectangle(corner_radius=val).scale(0.5)
            text = Text(str(val), size=0.3, stroke_width=0).next_to(rect, UP)
            return VGroup(rect,text)

        rects = VGroup(*[get_rect(v) for v in values])      
        rects.arrange(RIGHT)

        self.add(rects)
        self.wait()

 


Next: [05-3-F] Arc series: Arc/ArcBetweenPoints/CurvedArrow

 

[05-3-F] Arc series: Arc/ArcBetweenPoints/CurvedArrow

The arc's representative class is Arc, and the Circle and Dot classes inherit it. Here, we mainly focus on the Arc, ArcBetweenPoints, CurvedArrow, Circle, and Dot classes, and the rest..

infograph.tistory.com

Go To: [99] Table of Contents

반응형