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 PyGame window - Alternatively, copy
g2d_web.py
in that location and rename the file asg2d.py
; this will draw into a browser window
- 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 canvasclose_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
(pos: (int, int), size: (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
(src: str, pos: (int, int))
: Blit a whole image, given its name and the positiondraw_image_clip
(src: str, clip_pos: (int, int), clip_size: (int, int), pos: (int, int))
: Blit a portion of an imageload_audio
(src: str) -> str
: Load a sound and return a name for itplay_audio
(src: str, loop: bool)
: Play a sound, possibly in a loop, given its namepause_audio
(src: str)
: Stop playing a sound, given its name
mouse_position
() -> (int, int)
: Get current mouse positionmouse_clicked
() -> bool
: Check if left mouse button has been clickedcurrent_keys
() -> set
: Get all keys that are currently held downprompt
(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