Add RLCD animations and screensavers
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
# Standalone MicroPython Voice Animation: ACK / Received
|
||||
# Exposes run(text="", frames=...) and runs automatically if executed directly.
|
||||
import time
|
||||
|
||||
try:
|
||||
import board_config
|
||||
display = getattr(board_config, 'display_instance', None)
|
||||
except Exception:
|
||||
board_config = None
|
||||
display = None
|
||||
|
||||
def draw_center_text(d, msg, y, w, scale=1, c=1):
|
||||
char_w = 8 * scale
|
||||
x = max(0, (w - len(msg) * char_w) // 2)
|
||||
if hasattr(d, 'text_large') and scale > 1:
|
||||
try:
|
||||
d.text_large(msg, x, y, scale, c)
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
d.text(msg, x, y, c)
|
||||
|
||||
def run(text="", frames=100):
|
||||
if not display:
|
||||
print("board_config.display_instance is not available. Skipping animation.")
|
||||
return
|
||||
|
||||
width = getattr(display, 'width', 400)
|
||||
height = getattr(display, 'height', 300)
|
||||
cx, cy = width // 2, height // 2
|
||||
|
||||
label = text if text else "GOT IT"
|
||||
frame = 0
|
||||
|
||||
try:
|
||||
while True:
|
||||
if frames is not None and frames > 0 and frame >= frames:
|
||||
break
|
||||
|
||||
display.clear(0)
|
||||
|
||||
# Draw a thick checkmark in the center
|
||||
display.line(cx - 24, cy + 4, cx - 6, cy + 22, 1)
|
||||
display.line(cx - 23, cy + 4, cx - 5, cy + 22, 1)
|
||||
display.line(cx - 6, cy + 22, cx + 30, cy - 14, 1)
|
||||
display.line(cx - 5, cy + 22, cx + 31, cy - 14, 1)
|
||||
|
||||
# Concentric pulsing squares radiating outwards
|
||||
for p in range(3):
|
||||
# Scale pulse radius based on frame count
|
||||
r = 30 + ((frame * 4 + p * 30) % 90)
|
||||
display.rect(cx - r, cy - r, r * 2, r * 2, 1)
|
||||
|
||||
# Draw centered text label at the bottom
|
||||
draw_center_text(display, label, height - 30, width, scale=1, c=1)
|
||||
|
||||
display.show()
|
||||
frame += 1
|
||||
|
||||
try:
|
||||
time.sleep_ms(50)
|
||||
except AttributeError:
|
||||
time.sleep(0.05)
|
||||
except KeyboardInterrupt:
|
||||
print("Animation interrupted by user.")
|
||||
|
||||
if __name__ in ('__main__', '__name__'):
|
||||
run()
|
||||
Reference in New Issue
Block a user