Learn Before
  • Drawing Rectangles in Pygame

Customizing the Border Radius on Rectangles in Pygame

There are optional parameters for specifying the radius of the rectangle's border when calling the draw.rect() function. You can set the radius of the entire rectangle's border or a specific corner (top right, top left, bottom right, or bottom left). This allows you to round a part of your rectangle's border. The supported range is 0 to min(height, width) / 2, with 0 being an unrounded border.

pygame.draw.rect(surface, color, pygame.Rect(30, 30, 60, 60), width=0, border_radius=15) #this draws the roundest possible rectangle since it's min(height, width) / 2. pygame.draw.rect(surface, color, pygame.Rect(30, 30, 60, 60), width=0, border_radius=0, border_bottom_right_radius=15) #this draws a rectangle that is unrounded on all corners except for the bottom right

0

1

4 years ago

Tags

Python Programming Language

Data Science

Related
  • Customizing the Border Radius on Rectangles in Pygame