2021-04-15 09:21:27 +01:00
|
|
|
import time
|
|
|
|
import math
|
2022-07-07 09:37:47 +01:00
|
|
|
from picographics import PicoGraphics, DISPLAY_ROUND_LCD_240X240
|
2021-03-30 15:15:13 +01:00
|
|
|
|
2022-07-07 09:37:47 +01:00
|
|
|
display = PicoGraphics(display=DISPLAY_ROUND_LCD_240X240)
|
2021-03-30 15:15:13 +01:00
|
|
|
display.set_backlight(1.0)
|
|
|
|
|
2022-07-07 09:37:47 +01:00
|
|
|
WIDTH, HEIGHT = display.get_bounds()
|
2022-05-12 18:40:37 +01:00
|
|
|
RADIUS = WIDTH // 2
|
2021-03-30 15:15:13 +01:00
|
|
|
|
2022-07-07 09:37:47 +01:00
|
|
|
BLACK = display.create_pen(0, 0, 0)
|
|
|
|
|
2021-04-15 09:21:27 +01:00
|
|
|
|
2021-03-30 15:15:13 +01:00
|
|
|
def hsv_to_rgb(h, s, v):
|
|
|
|
if s == 0.0:
|
|
|
|
return v, v, v
|
2021-04-15 09:21:27 +01:00
|
|
|
i = int(h * 6.0) # XXX assume int() truncates!
|
2021-03-30 15:15:13 +01:00
|
|
|
f = (h * 6.0) - i
|
|
|
|
p = v * (1.0 - s)
|
|
|
|
q = v * (1.0 - s * f)
|
|
|
|
t = v * (1.0 - s * (1.0 - f))
|
|
|
|
i = i % 6
|
|
|
|
if i == 0:
|
|
|
|
return v, t, p
|
|
|
|
if i == 1:
|
|
|
|
return q, v, p
|
|
|
|
if i == 2:
|
|
|
|
return p, v, t
|
|
|
|
if i == 3:
|
|
|
|
return p, q, v
|
|
|
|
if i == 4:
|
|
|
|
return t, p, v
|
|
|
|
if i == 5:
|
|
|
|
return v, p, q
|
|
|
|
|
2021-04-15 09:21:27 +01:00
|
|
|
|
2021-03-30 15:15:13 +01:00
|
|
|
t = 0
|
2021-04-15 09:21:27 +01:00
|
|
|
|
2021-03-30 15:15:13 +01:00
|
|
|
while True:
|
2022-07-07 09:37:47 +01:00
|
|
|
display.set_pen(BLACK)
|
2021-03-30 15:15:13 +01:00
|
|
|
display.clear()
|
|
|
|
|
|
|
|
angle = t % (math.pi * 2)
|
2021-04-15 09:21:27 +01:00
|
|
|
|
2021-03-30 15:15:13 +01:00
|
|
|
prev_x = RADIUS
|
|
|
|
prev_y = RADIUS
|
|
|
|
|
|
|
|
steps = 30.0
|
|
|
|
angle_step = 0.5
|
2021-04-15 09:21:27 +01:00
|
|
|
|
2021-03-30 15:15:13 +01:00
|
|
|
for step in range(int(steps)):
|
|
|
|
angle += angle_step
|
|
|
|
|
|
|
|
distance = RADIUS / steps * step
|
|
|
|
distance += step * 0.2
|
|
|
|
|
|
|
|
r, g, b = [int(c * 255) for c in hsv_to_rgb((t / 10.0) + distance / 120.0, 1.0, 1.0)]
|
|
|
|
|
|
|
|
x = RADIUS + int(distance * math.cos(angle))
|
|
|
|
y = RADIUS + int(distance * math.sin(angle))
|
|
|
|
|
2021-04-15 09:21:27 +01:00
|
|
|
radius = ((math.sin(t + angle) + 1) / 2.0) * 10
|
2022-07-07 09:37:47 +01:00
|
|
|
dot_colour = display.create_pen(r, g, b)
|
|
|
|
display.set_pen(dot_colour)
|
2021-04-15 09:21:27 +01:00
|
|
|
display.circle(int(x), int(y), int(radius))
|
2021-03-30 15:15:13 +01:00
|
|
|
|
|
|
|
prev_x = x
|
|
|
|
prev_y = y
|
2021-04-15 09:21:27 +01:00
|
|
|
|
2021-03-30 15:15:13 +01:00
|
|
|
display.update()
|
|
|
|
time.sleep(0.02)
|
2021-04-15 09:21:27 +01:00
|
|
|
t += 0.02
|