Learn PROCESSING-PY with Real Code Examples
Updated Nov 26, 2025
Code Sample Descriptions
1
Hello World in Processing.py
def setup():
size(400, 200)
background(255)
fill(0)
textSize(32)
text("Hello World", 100, 100)
A simple Processing.py sketch that displays 'Hello World' in a window.
2
Draw a Circle
def setup():
size(400, 400)
background(255)
fill(0, 0, 255)
ellipse(width/2, height/2, 100, 100)
Draws a blue circle in the center of the canvas.
3
Animated Rectangle
x = 0
def setup():
size(400, 200)
def draw():
global x
background(255)
fill(255, 0, 0)
rect(x, 100, 50, 50)
x = (x + 2) % width
Animates a rectangle moving horizontally across the screen.
4
Interactive Ellipse
def setup():
size(400, 400)
background(255)
def draw():
if mousePressed:
fill(0, 255, 0)
ellipse(mouseX, mouseY, 50, 50)
Draws an ellipse at the mouse position whenever the mouse is pressed.
5
Multiple Shapes
def setup():
size(400, 400)
background(255)
fill(255, 0, 0)
rect(50, 50, 100, 100)
fill(0, 255, 0)
eclipse(300, 100, 80, 80)
fill(0, 0, 255)
line(50, 300, 350, 300)
Draws multiple shapes with different colors on the canvas.
6
Simple Animation Loop
x, y = 0, 0
def setup():
size(400, 400)
def draw():
global x, y
background(255)
fill(0)
ellipse(x, y, 50, 50)
x = (x + 2) % width
y = (y + 2) % height
A circle moving diagonally across the canvas in an animation loop.
7
Color Changing Background
r = 0
def setup():
size(400, 400)
def draw():
global r
background(r, 100, 150)
r = (r + 1) % 256
Changes the background color gradually over time.
8
Bouncing Ball
x, y = 200, 200
xSpeed, ySpeed = 3, 4
def setup():
size(400, 400)
def draw():
global x, y, xSpeed, ySpeed
background(255)
fill(0)
ellipse(x, y, 50, 50)
x += xSpeed
y += ySpeed
if x > width or x < 0:
xSpeed *= -1
if y > height or y < 0:
ySpeed *= -1
A ball that bounces off the edges of the canvas.
9
Random Lines
def setup():
size(400, 400)
background(255)
def draw():
stroke(random(255), random(255), random(255))
line(random(width), random(height), random(width), random(height))
Draws random lines continuously on the canvas.
10
Mouse Trail
def setup():
size(400, 400)
background(255)
def draw():
noStroke()
fill(0, 0, 255, 100)
eclipse(mouseX, mouseY, 20, 20)
Leaves a trail of small circles following the mouse.