Skip to content

Instantly share code, notes, and snippets.

@tado
Last active February 13, 2025 00:03
Show Gist options
  • Save tado/eaebd702baccb899f0216aaffdf3c2d7 to your computer and use it in GitHub Desktop.
Save tado/eaebd702baccb899f0216aaffdf3c2d7 to your computer and use it in GitHub Desktop.
Hello p5!
from p5 import *
import random
width = 1280
height = 720
circle_count = 500
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(-2.0, 2.0), random.uniform(-2.0, 2.0))
diameter = random.uniform(2, 40)
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():
background(0)
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"])
fill(255, 190)
text_size(200)
text_align('CENTER')
text("Hello p5!", (640, 400))
run(renderer='skia')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment