Rectangle¶
- draw_text.add_rectangle(sx: int, sy: int, w: int, h: int, color: int, display_duration: float, layer: int = 1) int¶
Add a rectangle element to the screen.
- Parameters:
sx – X-coordinate of the upper-left corner.
sy – Y-coordinate of the upper-left corner.
w – Width of the rectangle.
h – Height of the rectangle.
color – Rectangle color. Must be created with argb(…) or taken from the Colors class.
display_duration – How long the element remains on screen (in seconds).
layer – Rendering layer of the element. Higher layers appear above lower ones. Default is 1.
- Returns:
ID of the created element.
- draw_text.add_rectangle_from_corners(sx: int, sy: int, ex: int, ey: int, color: int, display_duration: float, layer: int = 1) int¶
Add a rectangle element to the screen.
- Parameters:
sx – X-coordinate of the upper-left corner.
sy – Y-coordinate of the upper-left corner.
ex – X-coordinate of the bottom-right corner.
ey – Y-coordinate of the bottom-right corner.
color – Rectangle color. Must be created with argb(…) or taken from the Colors class.
display_duration – How long the element remains on screen (in seconds).
layer – Rendering layer of the element. Higher layers appear above lower ones. Default is 1.
- Returns:
ID of the created element.
- draw_text.animate_rectangle(_id: int, func: Callable[[RectangleObject], None]) None¶
Animates the rectangle element with the given id by calling the given function every frame with the rectangle element as the argument.
- Parameters:
_id – ID of the rectangle element to animate.
func – Function to use to animate the rectangle element. The function is called every frame with the rectangle element as the argument.
- draw_text.modify_rectangle(_id: int, func: Callable[[RectangleObject], None]) None¶
Modifies the rectangle element with the given id by calling the given function once with the rectangle element as the argument.
- Parameters:
_id – ID of the rectangle element to modify.
func – Function to use to modify the rectangle element. The function is called on the closest render frame.
RectangleObject class¶
- class draw_text.RectangleObject(_id: int)¶
This class represents a text element. To create a TextObject object, call the constructor with the id of the text element.
- start_x: int¶
X-coordinate of the upper-left corner.
- start_y: int¶
Y-coordinate of the upper-left corner.
- end_x: int¶
X-coordinate of the bottom-right corner.
- end_y: int¶
Y-coordinate of the bottom-right corner.
- color: int¶
Rectangle color. Must be created by the [argb]() function or from the [Colors]() class.
- display_duration_modifier: float¶
Modifier to the
display_durationproperty.
- layer: int¶
Layer of the element.
- property display_duration¶
Time in seconds that the element will remain on screen. This property cannot be assigned, use
display_duration_modifierto change this value.
- update(_id: int)¶
Updates this RectangleObject with the values of the rectangle element specified by _id.
- Parameters:
_id – ID of the rectangle element.
- to_list() list¶
Returns a list containing all the values of this RectangleObject.
- Returns:
List containing all the values of this RectangleObject.
Example¶
1from draw_text import *
2
3add_rectangle(sx=10, sy=10, w=40, h=10, color=Colors.RED, display_duration=5)
4rect_id = add_rectangle_from_corners(sx=10, sy=40, ex=20, ey=60, color=Colors.YELLOW, display_duration=5)
5
6animate_text(rect_id, rainbow_animation) # Uses built-in rainbow animation