From 35bec326dfcc41d874fb2334bd1da377be92b57d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Wed, 11 Dec 2024 07:55:49 +0100 Subject: [PATCH] Pygame --- README.md | 3 ++- index.html | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 654f3be..cd46070 100644 --- a/README.md +++ b/README.md @@ -2991,6 +2991,7 @@ simpleaudio.play_buffer(samples_i, 1, 2, F).wait_done() Pygame ------ +#### Opes a window and draws a square that can be moved with arrow keys: ```python # $ pip3 install pygame import pygame as pg @@ -3006,6 +3007,7 @@ while not pg.event.get(pg.QUIT): screen.fill(pg.Color('black')) pg.draw.rect(screen, pg.Color('white'), rect) pg.display.flip() +pg.quit() ``` ### Rect @@ -3054,7 +3056,6 @@ arc(, color, , from_rad, to_rad) # Also ellipse(, color, , color, , width=0) # Also polygon(, color, points, width=0). ``` -### Font ```python = pg.font.Font(, size) # Loads TTF file. Pass None for default font. = .render(text, antialias, color) # Background color can be specified at the end. diff --git a/index.html b/index.html index b375f4a..40f7a27 100644 --- a/index.html +++ b/index.html @@ -2435,7 +2435,7 @@ simpleaudio.play_buffer(samples_i, 1, -

#Pygame

# $ pip3 install pygame
+

#Pygame

Opes a window and draws a square that can be moved with arrow keys:

# $ pip3 install pygame
 import pygame as pg
 
 pg.init()
@@ -2449,7 +2449,9 @@ rect = pg.Rect(240, 2
     screen.fill(pg.Color('black'))
     pg.draw.rect(screen, pg.Color('white'), rect)
     pg.display.flip()
-
+pg.quit() +
+

Rect

Object for storing rectangular coordinates.

<Rect> = pg.Rect(x, y, width, height)           # Creates Rect object. Truncates passed floats.
 <int>  = <Rect>.x/y/centerx/centery/…           # Top, right, bottom, left. Allows assignments.
@@ -2485,10 +2487,9 @@ line(<Surf>, color, (x1, y1), (x2, y2), width)  # Also ellipse(<Surf>, color, <Rect>, width=0).
 rect(<Surf>, color, <Rect>, width=0)            # Also polygon(<Surf>, color, points, width=0).
 
-

Font

<Font> = pg.font.Font(<path/file>, size)        # Loads TTF file. Pass None for default font.
+
<Font> = pg.font.Font(<path/file>, size)        # Loads TTF file. Pass None for default font.
 <Surf> = <Font>.render(text, antialias, color)  # Background color can be specified at the end.
-
- +

Sound

<Sound> = pg.mixer.Sound(<path/file/bytes>)     # WAV file or bytes/array of signed shorts.
 <Sound>.play/stop()                             # Also set_volume(<float>), fadeout(msec).