http://tomamic.github.io/fondinfo/
Python and C++ examples
Copyleft (ษ) 2008-2020 Michele Tomaiuolo - http://sowide.unipr.it/tomamic
This software is free - License: http://www.gnu.org/licenses/gpl-3.0.txt
- Copy
g2d.py
fromexamples
into the same folder containing your scripts; this will draw into a browser window - Alternatively, copy
g2d_pyg.py
in that location and rename the file asg2d.py
; this will use PyGame
- A
point
or asize
is a tuple(x, y)
- A
rect
is a tuple(x, y, w, h)
- A
color
is a tuple(r, g, b)
init_canvas
(size: (int, int))
: Initialize the drawing canvasmain_loop
(tick=None, fps=30)
: Start the event loop, accepting an optionaltick
function, which will be called periodicallyclear_canvas
()
: Clear the canvasupdate_canvas
()
: Draw all pending graphics on the canvas, it is called automaticall after eachtick
close_canvas
()
: Close the canvas and exit the main loop
set_color
(color: (int, int, int))
: Set the drawing colordraw_line
(pt1: (int, int), pt2: (int, int))
: Draw a line frompt1
topt2
fill_circle
(center: (int, int), radius: int)
: Fill a circle, givencenter
andradius
fill_rect
(rect: (int, int, int, int))
: Fill a given rectangledraw_text
(txt: str, pos: (int, int), size: int)
: Draw a text, given the left-top position and the font px sizedraw_text_centered
(txt: str, pos: (int, int), size: int)
: Draw a centered text, given the position and the font px size
load_image
(src: str) -> str
: Load an image and return a name for itdraw_image
(image: str, pos: (int, int))
: Blit a whole image, given its name and the positiondraw_image_clip
(image: str, clip: (int, int, int, int), rect: (int, int, int, int))
: Blit a portion of an imageload_audio
(src: str) -> str
: Load a sound and return a name for itplay_audio
(audio: str, loop: bool)
: Play a sound, possibly in a loop, given its namepause_audio
(audio: str)
: Stop playing a sound, given its name
mouse_position
() -> (int, int)
: Get current mouse positionkey_pressed
(key: string) -> bool
: Check if a key has been pressed after lasttick
key_released
(key: string) -> bool
: Check if a key has been released after lasttick
prompt
(message: str) -> str
: Show a dialog for entering a line of textconfirm
(message: str) -> bool
: Show a dialog for confirming a decisionalert
(message: str)
: Show a dialog with a message