Last active
January 19, 2023 19:38
-
-
Save todbot/6222a0d8b4fc1d860fd7a195a4a940d8 to your computer and use it in GitHub Desktop.
showing vectorio use
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like
FullSizeRender.MOV