본문 바로가기

Programming/Manim Lectures

[05-1-B]Dimensional methods: get_width/height/top, set_width/height

반응형

get_width

manimlib.mobject.mobject.Mobject.get_width(self)

Gets the object's width, that is, the length in the x-axis direction. In Manim, the x-axis direction is between [-7.1, 7.1]. Therefore, the value of get_width is between [0,14.2]

 

Returns: object's width value
# Usage
w = obj.get_width()

set_width

manimlib.mobject.mobject.Mobject.set_width(self, width, stretch=False, **kwargs)

Change the horizontal length of the object, that is, the length in the x-axis direction . If the given argument value is larger than the current width of the object, it is enlarged, and if it is small, it is reduced.

At this time, the vertical size also changes proportionally. If you only want to change the width without changing the vertical size, you should set stretch=True.

 

Parameters: width  
	The width size to be set. The type is float. 
	If it is larger than the current width, the object is enlarged, 
	and if it is smaller, the object is reduced.
  
Parameters: stretch=False  
	False: When the width is changed, the height is also enlarged or reduced.
	True: When the width is changed, the height is not changed

Parameters: **kwargs  
	about_point: Specify the reference point when zooming.
	about_edge:  The direction that becomes the reference when zooming.
				 LEFT/RIGHT/UP/DOWN/UL/UR/DL/DR  
[Usage]

parts.set_width(FRAME_WIDTH - 1)

get_height

manimlib.mobject.mobject.Mobject.get_height(self)

Gets the vertical length of the object, that is, the length in the y-axis direction. In Manim, the y-axis direction is between [-4,4]. Therefore, the total length is a value between [0,8]

For reference, FRAME_HEIGH=8 is specified as the overall height of the screen.

 

Returns: the value of height. float type value

 

[Usage]
w = obj.get_height()

set_height

manimlib.mobject.mobject.Mobject.set_height(self, height, stretch=False, **kwargs)

Changes the vertical length of the object, that is, the length in the y-axis direction.

If the given argument value is larger than the object's current length, it is enlarged, and if it is small, it is reduced. At this time, the size of the width also changes proportionally. If you only want to change the height without changing the width, you should set stretch=True.

 

Parameters: height  
	Target height value. float type. 
	If it is larger than current size of the object it is enlarged, else it is reduced.
  
Parameters:  stretch=False  
	False: Enlarge or reduce the width as well 
	True: Don't change the width 

Parameters: **kwargs  
	about_point: Specify the reference point when zooming.
	about_edge: Direction to be used as a reference when zooming. 
				LEFT/RIGHT/UP/DOWN/UL/UR/DL/DR  
[Usage]

 label.set_height(0.75 * bar.get_height())

 


get_center/top/bottom/left/right

manimlib.mobject.mobject.Mobject.get_center(self)
manimlib.mobject.mobject.Mobject.get_top(self)
manimlib.mobject.mobject.Mobject.get_bottom(self)
manimlib.mobject.mobject.Mobject.get_left(self)
manimlib.mobject.mobject.Mobject.get_right(self)

Gets the position value of the main point of the object. The value is an array of numpy.

 

  • get_center : the center point of the object
  • get_top: the middle point of the top side of the object
  • get_bottom: the middle point of the bottom side of the object
  • get_left: the middle point of the left side of the object
  • get_right: the middle point of the right side of the object
Returns: the direction of the object. the value is array type of numpy

To draw an arrow from the letter "you" to the right side of the rectangle, as shown in the picture below, start at the left point of "you" and pass the right point of the rectangle slightly.

 

In other words, using the values of "you".get_left() and rect.get_right() makes it easy to position the arrows.

 

 

rect = Rectangle(width=1.5, height=1)
you_label = TextMobject("you")
you_label.next_to(rect, RIGHT, MED_LARGE_BUFF)
arrow = Arrow(you_label.get_left(), rect.get_right() + 0.5 * LEFT, buff=0.1)

Next:  [05-1-C]Aligning methods: align_to, arrange, arrange_in_grid

 

[05-1-C]Aligning methods: align_to, arrange, arrange_in_grid

align_to manimlib.mobject.mobject.Mobject.align_to(self, mobject_or_point, direction=ORIGIN) Arrange objects based on target objects or points. For example, if mob1.align_to(mob2, UP), ..

infograph.tistory.com

Go To: [99] Table of Contents

 

반응형