2021-04-23 10:10:55 +00:00
|
|
|
import time
|
|
|
|
import random
|
2021-04-22 23:44:27 +00:00
|
|
|
from breakout_colourlcd240x240 import BreakoutColourLCD240x240
|
|
|
|
|
|
|
|
width = BreakoutColourLCD240x240.WIDTH
|
|
|
|
height = BreakoutColourLCD240x240.HEIGHT
|
|
|
|
|
|
|
|
display_buffer = bytearray(width * height * 2) # 2-bytes per pixel (RGB565)
|
|
|
|
display = BreakoutColourLCD240x240(display_buffer)
|
|
|
|
|
|
|
|
display.set_backlight(1.0)
|
|
|
|
|
|
|
|
|
|
|
|
class Ball:
|
|
|
|
def __init__(self, x, y, r, dx, dy, pen):
|
|
|
|
self.x = x
|
|
|
|
self.y = y
|
|
|
|
self.r = r
|
|
|
|
self.dx = dx
|
|
|
|
self.dy = dy
|
|
|
|
self.pen = pen
|
|
|
|
|
2021-04-23 10:10:55 +00:00
|
|
|
|
2021-04-22 23:44:27 +00:00
|
|
|
# initialise shapes
|
|
|
|
balls = []
|
|
|
|
for i in range(0, 100):
|
|
|
|
r = random.randint(0, 10) + 3
|
|
|
|
balls.append(
|
|
|
|
Ball(
|
|
|
|
random.randint(r, r + (width - 2 * r)),
|
|
|
|
random.randint(r, r + (height - 2 * r)),
|
|
|
|
r,
|
|
|
|
(14 - r) / 2,
|
|
|
|
(14 - r) / 2,
|
2021-04-23 10:10:55 +00:00
|
|
|
display.create_pen(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)),
|
2021-04-22 23:44:27 +00:00
|
|
|
)
|
|
|
|
)
|
2021-04-23 10:10:55 +00:00
|
|
|
|
2021-04-22 23:44:27 +00:00
|
|
|
while True:
|
|
|
|
display.set_pen(40, 40, 40)
|
|
|
|
display.clear()
|
2021-04-23 10:10:55 +00:00
|
|
|
|
2021-04-22 23:44:27 +00:00
|
|
|
for ball in balls:
|
|
|
|
ball.x += ball.dx
|
|
|
|
ball.y += ball.dy
|
2021-04-23 10:10:55 +00:00
|
|
|
|
2021-04-22 23:44:27 +00:00
|
|
|
xmax = width - ball.r
|
|
|
|
xmin = ball.r
|
|
|
|
ymax = height - ball.r
|
|
|
|
ymin = ball.r
|
|
|
|
|
|
|
|
if ball.x < xmin or ball.x > xmax:
|
|
|
|
ball.dx *= -1
|
|
|
|
|
|
|
|
if ball.y < ymin or ball.y > ymax:
|
|
|
|
ball.dy *= -1
|
|
|
|
|
|
|
|
display.set_pen(ball.pen)
|
|
|
|
display.circle(int(ball.x), int(ball.y), int(ball.r))
|
|
|
|
|
|
|
|
display.update()
|
|
|
|
time.sleep(0.01)
|