Skip to content

Instantly share code, notes, and snippets.

@tadeubas
Last active September 28, 2023 16:21
Show Gist options
  • Save tadeubas/df2f734baddf77a8810904183ac90720 to your computer and use it in GitHub Desktop.
Save tadeubas/df2f734baddf77a8810904183ac90720 to your computer and use it in GitHub Desktop.
Krux screensaver
import lcd
from krux.display import Display
logo = """
██
██
██
██████
██
██ ██
██ ██
████
██ ██
██ ██
██ ██
"""[1:-1].split("\n")
disp = Display()
disp.initialize_lcd()
disp.clear()
disp.draw_centered_text(logo)
print("screensaver context!")
def draw_text_with_full_bg(
self,
line,
qtd_offset,
color,
bg_color,
):
"""Draws text with full screen bg_color on the display"""
lcd.fill_rectangle(0, qtd_offset * self.font_height, self.width(), self.font_height, bg_color)
offset_x = (self.width() - self.font_width * len(line)) // 2
offset_x = max(0, offset_x)
self.draw_string(
offset_x, (qtd_offset * self.font_height), line, color, bg_color
)
disp.draw_text_with_full_bg = draw_text_with_full_bg
for _ in range(3):
logo.insert(0,"")
logo.append("")
logo.append("")
anim_frame = 0
screensaver_time = 0
fg_color = 0x20FD
bg_color = 0xF800
lcd.clear()
while True:
if (screensaver_time + 150 < time.ticks_ms()):
screensaver_time = time.ticks_ms()
# show animation on the screeen
if (anim_frame <= len(logo)):
disp.draw_text_with_full_bg(disp, logo[anim_frame], anim_frame, color=fg_color, bg_color=bg_color)
anim_frame = anim_frame + 1
if (anim_frame > len(logo)*1.4):
anim_frame = 0
bg_color, fg_color = fg_color, bg_color
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment