diff --git a/preload/apps/lsd_nickname/__init__.py b/preload/apps/lsd_nickname/__init__.py index 59a04f7d14fa87aef9b6d8dfdde170b9d9f6cb76..8ac8be0f253fa1353344c39bdaaa7b334a95d6b5 100644 --- a/preload/apps/lsd_nickname/__init__.py +++ b/preload/apps/lsd_nickname/__init__.py @@ -1,46 +1,46 @@ -import display -import leds -import utime - -_rand = 123456789 - - -def rand(): - global _rand - _rand = (1103515245 * _rand + 12345) & 0xFFFFFF - return _rand - - -gs = 160 -colors = [((i >> 2) * gs, (i >> 1 & 1) * gs, (i & 1) * gs) for i in range(1, 8)] - -nick = "sample text" -try: - with open("/nickname.txt") as f: - nick = f.read() -except: - pass - -while True: - with display.open() as d: - for k in range(4): - (x1, y1) = (rand() % 159, rand() % 79) - (x2, y2) = (min(x1 + rand() % 40, 159), min(y1 + rand() % 40, 79)) - try: - d.rect(x1, y1, x2, y2, col=colors[rand() % len(colors)], filled=True) - except: - pass - fg = colors[rand() % len(colors)] - nx = 80 - round(len(nick) / 2 * 14) - d.print( - nick, - fg=fg, - bg=[0xFF - c for c in fg], - posx=(nx - 8) + rand() % 16, - posy=22 + rand() % 16, - ) - d.update() - d.close() - leds.set(rand() % 11, colors[rand() % len(colors)]) - leds.set_rocket(rand() % 3, rand() % 32) - utime.sleep_us(1) # Feed watch doge +import display +import leds +import utime + +_rand = 123456789 + + +def rand(): + global _rand + _rand = (1103515245 * _rand + 12345) & 0xFFFFFF + return _rand + + +gs = 160 +colors = [((i >> 2) * gs, (i >> 1 & 1) * gs, (i & 1) * gs) for i in range(1, 8)] + +nick = "sample text" +try: + with open("/nickname.txt") as f: + nick = f.read() +except: + pass + +while True: + with display.open() as d: + for k in range(4): + (x1, y1) = (rand() % 159, rand() % 79) + (x2, y2) = (min(x1 + rand() % 40, 159), min(y1 + rand() % 40, 79)) + try: + d.rect(x1, y1, x2, y2, col=colors[rand() % len(colors)], filled=True) + except: + pass + fg = colors[rand() % len(colors)] + nx = 80 - round(len(nick) / 2 * 14) + d.print( + nick, + fg=fg, + bg=[0xFF - c for c in fg], + posx=(nx - 8) + rand() % 16, + posy=22 + rand() % 16, + ) + d.update() + d.close() + leds.set(rand() % 11, colors[rand() % len(colors)]) + leds.set_rocket(rand() % 3, rand() % 32) + utime.sleep_us(1) # Feed watch doge diff --git a/preload/apps/scope/__init__.py b/preload/apps/scope/__init__.py index 39de256ca10ed117f95533fb7cea75582e8f104b..b4e861a7ac00b4c14cc14074b18955acaf93ccac 100644 --- a/preload/apps/scope/__init__.py +++ b/preload/apps/scope/__init__.py @@ -1,35 +1,35 @@ -import os -import display -import utime -import buttons -import light_sensor -import math - -WIDTH = 160 -HEIGHT = 80 - -disp = display.open() - -light_sensor.start() - -history = [] - -while True: - disp.clear() - - value = light_sensor.get_reading() - - history.insert(0, value) - if len(history) > WIDTH: - history.pop() - - disp.print("%i" % value) - - for i in range(0, len(history)): - # Rescale to range 0 <= value < HEIGHT-1 - y = math.floor(history[i] * (HEIGHT - 2) / max(history)) - - disp.pixel(WIDTH - i, HEIGHT - y - 1) - - disp.update() - utime.sleep(0.1) +import os +import display +import utime +import buttons +import light_sensor +import math + +WIDTH = 160 +HEIGHT = 80 + +disp = display.open() + +light_sensor.start() + +history = [] + +while True: + disp.clear() + + value = light_sensor.get_reading() + + history.insert(0, value) + if len(history) > WIDTH: + history.pop() + + disp.print("%i" % value) + + for i in range(0, len(history)): + # Rescale to range 0 <= value < HEIGHT-1 + y = math.floor(history[i] * (HEIGHT - 2) / max(history)) + + disp.pixel(WIDTH - i, HEIGHT - y - 1) + + disp.update() + utime.sleep(0.1)