Skip to content

Instantly share code, notes, and snippets.

@tado
Last active February 21, 2025 05:37
Show Gist options
  • Save tado/618ceb0ae144a890f182f2fffdb9fcf8 to your computer and use it in GitHub Desktop.
Save tado/618ceb0ae144a890f182f2fffdb9fcf8 to your computer and use it in GitHub Desktop.
Simple animation sketch for p5 python
from p5 import *
import random
width = 1280
height = 720
circle_count = 400
circles = []
def setup():
size(width, height)
no_stroke()
for _ in range(circle_count):
pos = Vector(random.uniform(0, width), random.uniform(0, height))
vel = Vector(random.uniform(-1.0, 1.0), random.uniform(-1.0, 1.0))
diameter = random.uniform(2, 32)
color = Color(random.uniform(0, 255),
random.uniform(0, 255),
random.uniform(0, 255), 190)
circles.append({'pos': pos, 'vel': vel, 'diameter': diameter, 'color': color})
def draw():
fill(0, 30)
rect((0, 0), width, height)
for c in circles:
fill(c["color"])
c["pos"] += c["vel"]
if c["pos"].x > width or c["pos"].x < 0:
c["vel"].x *= -1
if c["pos"].y > height or c["pos"].y < 0:
c["vel"].y *= -1
circle((c["pos"].x, c["pos"].y), c["diameter"])
run(renderer='skia')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment