A pygame wrapper to simplify the library's draw functions.
Project description
Ezshapes
Ezshapes is a Pygame wrapper made to facilitate ease in making shapes and scenes.
Getting Started
All of the functions ezshapes has is held under its renderer library. Simply import the tools from ezshapes.renderer
from ezshapes.renderer import *
Making a scene is as simple as choosing the size (measured in pixels). Set up your scene and decide on the name with the setup()
function.
After setup everything through ezshapes is rendered on screen per frame. Each frame is made through placing shapes in one iteration of a loop then drawing to it by using update_screen()
.
setup(SCREEN_HEIGHT, SCREEN_WIDTH, TITLE)
while True:
"""
Your code here!
"""
set_background('skyblue')
update_screen()
Any shapes can be placed within the main loop and before the update_screen()
call, which will be rendered on screen in the order they are processed. This means that two shapes in the same place can draw over one another if they overlap.
As ezshapes wraps around pygame, pygame events and such can still be checked inside of the main loop. The only thing currently inaccessible is the display surface.
All shapes accept a color, which can either be a hex digit string in the form of "#rrggbb"
or an accepted color string from pygame's color dictionary.
Functions
setup(width, height, name="Flying a UFO!")
Creates the display surface for the scene with the specified width and height, can optionally include a name for the window.
Argument | Type | Description |
---|---|---|
width | int | Width of the display screen in pixels |
height | int | Height of the display screen in pixels |
name | str (Optional) | Display name of the window |
update_screen()
Calls pygame.display.update()
draws to the screen.
Argument | Type | Description |
---|---|---|
None | -- | -- |
set_background(color='grey70')
Fills the screen with the given color. If given an not given an invalid color or no color, defaults to gray. Highly recommended to call this function before any shapes.
Argument | Type | Description |
---|---|---|
color | str | Color to fill the screen with. |
get_screen_width()
Return the width of the current display, equal to the width given to the setup()
function.
Argument | Type | Description |
---|---|---|
None | -- | -- |
Returns | Type | Description |
---|---|---|
width | int | Width of the screen in pixels |
get_screen_height()
Return the height of the current display, equal to the width given to the setup()
function.
Argument | Type | Description |
---|---|---|
None | -- | -- |
Returns | Type | Description |
---|---|---|
height | int | Height of the screen in pixels |
Shapes
rect(left, top, width, height, color)
Creates a rectangle on screen, starting from the top-left corner to the right and downwards by the width and height respectively. The rectangle is filled with one solid color, if the color is invalid it will default to gray.
Argument | Type | Description |
---|---|---|
left | int | x-coordinate for the top-left corner of the rectangle |
top | int | y-coordinate for the top-left corner of the rectangle |
width | int | Width of the rectangle extending right from the top-left corner |
height | int | Height of the rectangle extending downwards from the top-left corner |
color | str (Optional) | Solid color to fill the rectangle |
ellipse(centerx, centery, width, height, color)
Creates an ellipse on screen, stretching to either side of the center with the given width and height. The ellipse is filled with one solid color, if the color is considered invalid it will default to gray.
Argument | Type | Description |
---|---|---|
centerx | int | x-coordinate for the center of the ellipse |
centery | int | y-coordinate for the center of the ellipse |
width | int | Width of the ellipse extending outwards from the center |
height | int | Height of the ellipse extending outwards from the center |
color | str (Optional) | Solid color to fill the ellipse |
circle(centerx, centery, radius, color)
Creates a circle on screen, equivalent to making an ellipse with equal height and width.
Argument | Type | Description |
---|---|---|
centerx | int | x-coordinate for the center of the circle |
centery | int | y-coordinate for the center of the circle |
radius | int | Radius of the circle |
color | str (Optional) | Solid color to fill the circle |
triangle(p1x, p1y, p2x, p2y, p3x, p3y, color)
Creates a triangle on screen, drawn between 3 given points.
Argument | Type | Description |
---|---|---|
p1x | int | x-coordinate for the first vertex |
p1y | int | y-coordinate for the first vertex |
p2x | int | x-coordinate for the second vertex |
p2y | int | y-coordinate for the second vertex |
p3x | int | x-coordinate for the third vertex |
p3y | int | y-coordinate for the third vertex |
color | str (Optional) | Solid color to fill the ellipse |
line(p1x, p1y, p2x, p2y, width=1)
Draws a line on screen between two given points. A width less than 1 will result in nothing being drawn.
Argument | Type | Description |
---|---|---|
p1x | int | x-coordinate for the first point |
p1y | int | y-coordinate for the first point |
p2x | int | x-coordinate for the second point |
p2y | int | y-coordinate for the second point |
width | int | width of the line |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ezshapes-1.0.1.tar.gz
.
File metadata
- Download URL: ezshapes-1.0.1.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47a23fa3e35fc9a1289647a50869468249ce9c760a5743d7380a6a1046afee80 |
|
MD5 | f1eca7c90a288f22600880bf0f06d4de |
|
BLAKE2b-256 | d458d5faadf0f27246b1258cae3305c0a149075b0902dc71a48d4ca290c0efab |
File details
Details for the file ezshapes-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: ezshapes-1.0.1-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac9c8e3dfc9e382b4b7f5ffc8e649529a58b81653a4d175a1de914ccf62f0fc5 |
|
MD5 | dd312b25fb50eb7f857e41b01eceffb1 |
|
BLAKE2b-256 | c7b6b9c708dc9b85af3ecf2524f2623dd8fba282b8496c7a153f144a3fbaf1fb |