Skip to content

Instantly share code, notes, and snippets.

@todbot
Last active January 19, 2023 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todbot/6222a0d8b4fc1d860fd7a195a4a940d8 to your computer and use it in GitHub Desktop.
Save todbot/6222a0d8b4fc1d860fd7a195a4a940d8 to your computer and use it in GitHub Desktop.
showing vectorio use
# vectorio_balls.py -- show using vectorio.Circle
# 19 Jan 2023 - @todbot / Tod Kurt
import board, time, math, random
import displayio, vectorio, rainbowio
display = board.DISPLAY
disp_width,disp_height = display.width, display.height
screen = displayio.Group() # group that holds everything
display.show(screen) # add main group to display
num_balls = 10 # number of balls
r = 15 # radius of balls
balls = []
for i in range(num_balls):
palette = displayio.Palette(1)
palette[0] = rainbowio.colorwheel(random.randint(0,255)) # random color
x,y = random.randint(0,disp_width), random.randint(0,disp_height)
vx,vy = random.randint(-3,3), random.randint(-2,2) # random velocities
circle = vectorio.Circle(pixel_shader=palette, radius=r, x=x, y=y)
screen.append(circle) # add to display
balls.append( [circle, vx, vy] ) # store circle & velocities for later movement
while True:
for (ball,vx,vy) in balls:
ball.x = (ball.x + vx) % disp_width
ball.y = (ball.y + vy) % disp_height # wrap-around
time.sleep(0.05)
@todbot
Copy link
Author

todbot commented Jan 19, 2023

Looks like

FullSizeRender.MOV

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment