This document describes the public API exposed by from processing import *.
Notes:
- This project uses
snake_casefunction and variable names. - The API is inspired by Processing, with Python naming conventions.
Set the sketch window size in pixels.
Switch the sketch window to fullscreen mode.
Set the target frame rate for interactive mode.
Start the sketch loop.
Parameters:
mode=None: auto-detect mode.mode="interactive": requiressetup()anddraw().mode="static": renders once (or fromsetup()) and keeps window open.
Set the window title.
Set the window icon from an image file.
Fill the whole screen with a grayscale color.
Fill the whole screen with an RGB color.
Draw a rectangle.
Draw a circle using center (x, y) and diameter d.
Draw an ellipse centered at (x, y).
Draw a line segment.
Draw a single point.
Draw a triangle.
Draw a quadrilateral.
Draw an arc over an ellipse defined by center and size.
Draw a cubic Bezier curve.
Set grayscale fill color.
Set RGB fill color.
Disable fill.
Set grayscale stroke color.
Set RGB stroke color.
Disable stroke.
Set stroke thickness.
Return grayscale color tuple (r, r, r).
Return RGB color tuple.
Return RGBA color tuple.
Set text size.
Set text alignment.
Horizontal values:
LEFT,CENTER,RIGHT
Vertical values:
TOP,CENTER,BOTTOM,BASELINE
Draw text at a position.
Load and return a pygame.Surface from disk.
Draw an image.
Arguments:
img: apygame.Surfaceor an image path string.x, y: target position.w, h(optional): scale image to width and height.
Return elapsed milliseconds since window initialization.
Return a random float.
Forms:
random()->0.0 <= value < 1.0random(high)->0.0 <= value < highrandom(low, high)->low <= value < high(uniform float)
Format a number with zero-padded integer digits and fixed decimal digits.
Example:
nf(7.25, 4, 2)->"0007.25"
Start asynchronous console input. Returns True if started, False if a request is already pending.
Return True if an async console input request is pending.
Alignment constants:
LEFTRIGHTCENTERTOPBOTTOMBASELINE
Use these with text_align(...).
These variables are updated by the runtime loop:
widthheightdisplay_widthdisplay_heightpixel_widthpixel_height
frame_countfocused
mouse_xmouse_ypmouse_xpmouse_yis_mouse_pressedmouse_button
keykey_codeis_key_pressed
Define any of these in your sketch file when needed:
setup()draw()key_pressed(key)key_released(key)key_typed(char)mouse_pressed(x, y, button)mouse_released(x, y, button)mouse_clicked(x, y, button)mouse_moved(x, y, dx, dy)mouse_dragged(x, y, dx, dy)mouse_wheel(dx, dy)input_received(text)input_error(err)
from processing import *
x = 0
def setup():
size(800, 500)
frame_rate(60)
def draw():
global x
background(245)
fill(80, 170, 255)
no_stroke()
circle(x, 250, 40)
x += 2
run()