kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Merge 3d2fa5d8a5
into 32c10482d9
commit
7502f287c8
|
@ -1,6 +1,7 @@
|
|||
import time
|
||||
from galactic import GalacticUnicorn
|
||||
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY
|
||||
# import random
|
||||
|
||||
'''
|
||||
Display scrolling wisdom, quotes or greetz.
|
||||
|
@ -27,15 +28,16 @@ height = GalacticUnicorn.HEIGHT
|
|||
|
||||
# function for drawing outlined text
|
||||
def outline_text(text, x, y):
|
||||
graphics.set_pen(graphics.create_pen(int(OUTLINE_COLOUR[0]), int(OUTLINE_COLOUR[1]), int(OUTLINE_COLOUR[2])))
|
||||
graphics.text(text, x - 1, y - 1, -1, 1)
|
||||
graphics.text(text, x, y - 1, -1, 1)
|
||||
graphics.text(text, x + 1, y - 1, -1, 1)
|
||||
graphics.text(text, x - 1, y, -1, 1)
|
||||
graphics.text(text, x + 1, y, -1, 1)
|
||||
graphics.text(text, x - 1, y + 1, -1, 1)
|
||||
graphics.text(text, x, y + 1, -1, 1)
|
||||
graphics.text(text, x + 1, y + 1, -1, 1)
|
||||
if (OUTLINE_COLOUR != BACKGROUND_COLOUR):
|
||||
graphics.set_pen(graphics.create_pen(int(OUTLINE_COLOUR[0]), int(OUTLINE_COLOUR[1]), int(OUTLINE_COLOUR[2])))
|
||||
graphics.text(text, x - 1, y - 1, -1, 1)
|
||||
graphics.text(text, x, y - 1, -1, 1)
|
||||
graphics.text(text, x + 1, y - 1, -1, 1)
|
||||
graphics.text(text, x - 1, y, -1, 1)
|
||||
graphics.text(text, x + 1, y, -1, 1)
|
||||
graphics.text(text, x - 1, y + 1, -1, 1)
|
||||
graphics.text(text, x, y + 1, -1, 1)
|
||||
graphics.text(text, x + 1, y + 1, -1, 1)
|
||||
|
||||
graphics.set_pen(graphics.create_pen(int(MESSAGE_COLOUR[0]), int(MESSAGE_COLOUR[1]), int(MESSAGE_COLOUR[2])))
|
||||
graphics.text(text, x, y, -1, 1)
|
||||
|
@ -47,6 +49,9 @@ gu.set_brightness(0.5)
|
|||
STATE_PRE_SCROLL = 0
|
||||
STATE_SCROLLING = 1
|
||||
STATE_POST_SCROLL = 2
|
||||
LENGTH_TO_TRIGGER_PARTIAL_RENDER = 50
|
||||
CHARS_TO_RENDER = 30
|
||||
CHARS_LEFT_RESET = 5
|
||||
|
||||
shift = 0
|
||||
state = STATE_PRE_SCROLL
|
||||
|
@ -59,6 +64,14 @@ msg_width = graphics.measure_text(MESSAGE, 1)
|
|||
|
||||
last_time = time.ticks_ms()
|
||||
|
||||
message_display = MESSAGE
|
||||
partial_text = 0
|
||||
if (len(message_display) > LENGTH_TO_TRIGGER_PARTIAL_RENDER):
|
||||
partial_text = 1
|
||||
message_display = MESSAGE[0:CHARS_TO_RENDER]
|
||||
current_char = 0
|
||||
msg_width = graphics.measure_text(message_display, 1)
|
||||
|
||||
while True:
|
||||
time_ms = time.ticks_ms()
|
||||
|
||||
|
@ -77,17 +90,32 @@ while True:
|
|||
shift += 1
|
||||
if shift >= (msg_width + PADDING * 2) - width - 1:
|
||||
state = STATE_POST_SCROLL
|
||||
current_char = 0
|
||||
message_display = MESSAGE[0:CHARS_TO_RENDER]
|
||||
last_time = time_ms
|
||||
|
||||
if state == STATE_POST_SCROLL and time_ms - last_time > HOLD_TIME * 1000:
|
||||
state = STATE_PRE_SCROLL
|
||||
# MESSAGE_COLOUR = (random.randint(0,255), random.randint(0,255), random.randint(0,255)) # Uncomment this and the random import to make the display a new colour each rotation
|
||||
shift = 0
|
||||
last_time = time_ms
|
||||
|
||||
if (partial_text == 1 and PADDING - shift < -10):
|
||||
char_size = graphics.measure_text(message_display[0:1], 1)
|
||||
if (message_display[0:1] == ' '):
|
||||
char_size -= 1
|
||||
shift -= char_size
|
||||
current_char += 1
|
||||
|
||||
message_display = MESSAGE[current_char:current_char + CHARS_TO_RENDER]
|
||||
if (len(message_display) < CHARS_LEFT_RESET):
|
||||
state = STATE_POST_SCROLL
|
||||
last_time = time_ms
|
||||
|
||||
graphics.set_pen(graphics.create_pen(int(BACKGROUND_COLOUR[0]), int(BACKGROUND_COLOUR[1]), int(BACKGROUND_COLOUR[2])))
|
||||
graphics.clear()
|
||||
|
||||
outline_text(MESSAGE, x=PADDING - shift, y=2)
|
||||
outline_text(message_display, x=PADDING - shift, y=2)
|
||||
|
||||
# update the display
|
||||
gu.update(graphics)
|
||||
|
|
Ładowanie…
Reference in New Issue