2021-04-15 08:21:27 +00:00
|
|
|
import time
|
|
|
|
import math
|
2021-03-30 14:15:13 +00:00
|
|
|
from breakout_roundlcd import BreakoutRoundLCD
|
|
|
|
|
|
|
|
width = BreakoutRoundLCD.WIDTH
|
|
|
|
height = BreakoutRoundLCD.HEIGHT
|
|
|
|
|
|
|
|
display_buffer = bytearray(width * height * 2) # 2-bytes per pixel (RGB565)
|
|
|
|
display = BreakoutRoundLCD(display_buffer)
|
|
|
|
|
|
|
|
display.set_backlight(1.0)
|
|
|
|
|
|
|
|
RADIUS = width // 2
|
|
|
|
|
2021-04-15 08:21:27 +00:00
|
|
|
|
2021-03-30 14:15:13 +00:00
|
|
|
def hsv_to_rgb(h, s, v):
|
|
|
|
if s == 0.0:
|
|
|
|
return v, v, v
|
2021-04-15 08:21:27 +00:00
|
|
|
i = int(h * 6.0) # XXX assume int() truncates!
|
2021-03-30 14:15:13 +00: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 08:21:27 +00:00
|
|
|
|
2021-03-30 14:15:13 +00:00
|
|
|
t = 0
|
2021-04-15 08:21:27 +00:00
|
|
|
|
2021-03-30 14:15:13 +00:00
|
|
|
while True:
|
|
|
|
display.set_pen(0, 0, 0)
|
|
|
|
display.clear()
|
|
|
|
|
|
|
|
angle = t % (math.pi * 2)
|
2021-04-15 08:21:27 +00:00
|
|
|
|
2021-03-30 14:15:13 +00:00
|
|
|
prev_x = RADIUS
|
|
|
|
prev_y = RADIUS
|
|
|
|
|
|
|
|
steps = 30.0
|
|
|
|
angle_step = 0.5
|
2021-04-15 08:21:27 +00:00
|
|
|
|
2021-03-30 14:15:13 +00: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 08:21:27 +00:00
|
|
|
radius = ((math.sin(t + angle) + 1) / 2.0) * 10
|
2021-03-30 14:15:13 +00:00
|
|
|
display.set_pen(r, g, b)
|
2021-04-15 08:21:27 +00:00
|
|
|
display.circle(int(x), int(y), int(radius))
|
2021-03-30 14:15:13 +00:00
|
|
|
|
|
|
|
prev_x = x
|
|
|
|
prev_y = y
|
2021-04-15 08:21:27 +00:00
|
|
|
|
2021-03-30 14:15:13 +00:00
|
|
|
display.update()
|
|
|
|
time.sleep(0.02)
|
2021-04-15 08:21:27 +00:00
|
|
|
t += 0.02
|