Good thought.
I wasn’t seeing it with the balls example, but when I changed them to squares and upped the speed a little bit, it was back. I think its just harder to see with a circle cause they don’t have straight lines.
This sort of gave me an idea for a workaround. I can append circles to the ends of my rectangles and make them bubbles or draw thick lines instead of rectangles. I’ll let you know how it goes.
Square Balls Code, lol.
import time
import random
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY_2, PEN_P8
from pimoroni import RGBLED, Button
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY_2, pen_type=PEN_P8)
display.set_backlight(1.0)
WIDTH, HEIGHT = display.get_bounds()
led = RGBLED(6, 7, 8)
led.set_rgb(0, 0, 0)
button_a = Button(12)
button_b = Button(13)
button_x = Button(14)
button_y = Button(15)
# We're creating 100 balls with their own individual colour and 1 BG colour
# for a total of 101 colours, which will all fit in the custom 256 entry palette!
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
# initialise shapes
balls = []
for i in range(0, 20):
r = random.randint(5, 15) + 3
balls.append(
Ball(
random.randint(r, r + (WIDTH - 2 * r)),
random.randint(r, r + (HEIGHT - 2 * r)),
r*2,
(14 - r) / 2,
(14 - r) / 2,
display.create_pen(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)),
)
)
BG = display.create_pen(40, 40, 40)
while True:
if button_a.read():
led.set_rgb(255, 0, 0)
elif button_b.read():
led.set_rgb(0, 155, 0)
elif button_x.read():
led.set_rgb(0, 0, 0)
elif button_y.read():
led.set_rgb(0, 0, 255)
display.set_pen(BG)
display.clear()
for ball in balls:
ball.x += ball.dx
ball.y += ball.dy
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.rectangle(int(ball.x), int(ball.y), int(ball.r),int(ball.r))
display.update()
time.sleep(0.01)