aboutsummaryrefslogtreecommitdiff
path: root/NeoRuntime/builtin/strandtest/script.py
diff options
context:
space:
mode:
authorJakob Stendahl <jakob.stendahl@outlook.com>2021-09-19 19:43:11 +0200
committerJakob Stendahl <jakob.stendahl@outlook.com>2021-09-19 19:43:11 +0200
commit7bdce37fd3f18e2712e18c4e2c64cac69af0aca1 (patch)
treeb7ad3f1cca92e2dfd2664ae9e65652bd03ff58b2 /NeoRuntime/builtin/strandtest/script.py
parente6880cd8ccf82d993f222cb14b4860581654acb8 (diff)
downloadLuxcena-Neo-7bdce37fd3f18e2712e18c4e2c64cac69af0aca1.tar.gz
Luxcena-Neo-7bdce37fd3f18e2712e18c4e2c64cac69af0aca1.zip
:boom: Introduce new UI based on svelte, and rewrite a lot of the node app and the NeoRuntime
Diffstat (limited to 'NeoRuntime/builtin/strandtest/script.py')
-rw-r--r--NeoRuntime/builtin/strandtest/script.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/NeoRuntime/builtin/strandtest/script.py b/NeoRuntime/builtin/strandtest/script.py
new file mode 100644
index 0000000..f7d013a
--- /dev/null
+++ b/NeoRuntime/builtin/strandtest/script.py
@@ -0,0 +1,76 @@
+from luxcena_neo import NeoBehaviour, util
+import time
+
+def colorWipe(*color, wait_ms=50):
+ """Wipe color across display a pixel at a time."""
+ for i in range(strip.num_pixels()):
+ strip.set_pixel_color(i, *color)
+ strip.show()
+ time.sleep(wait_ms/1000.0)
+
+def theaterChase(*color, wait_ms=50, iterations=10):
+ """Movie theater light style chaser animation."""
+ for j in range(iterations):
+ for q in range(3):
+ for i in range(0, strip.num_pixels(), 3):
+ strip.set_pixel_color(i+q, *color)
+ strip.show()
+ time.sleep(wait_ms/1000.0)
+ for i in range(0, strip.num_pixels(), 3):
+ strip.set_pixel_color(i+q, 0)
+
+def wheel(pos):
+ """Generate rainbow colors across 0-255 positions."""
+ if pos < 85:
+ return Color(pos * 3, 255 - pos * 3, 0)
+ elif pos < 170:
+ pos -= 85
+ return Color(255 - pos * 3, 0, pos * 3)
+ else:
+ pos -= 170
+ return Color(0, pos * 3, 255 - pos * 3)
+
+def rainbow(wait_ms=20, iterations=1):
+ """Draw rainbow that fades across all pixels at once."""
+ for j in range(256*iterations):
+ for i in range(strip.num_pixels()):
+ strip.set_pixel_color(i, wheel((i+j) & 255))
+ strip.show()
+ time.sleep(wait_ms/1000.0)
+
+def rainbowCycle(wait_ms=20, iterations=5):
+ """Draw rainbow that uniformly distributes itself across all pixels."""
+ for j in range(256*iterations):
+ for i in range(strip.num_pixels()):
+ strip.set_pixel_color(i, wheel(((i * 256 / strip.num_pixels()) + j) & 255))
+ strip.show()
+ time.sleep(wait_ms/1000.0)
+
+def theaterChaseRainbow(wait_ms=50):
+ """Rainbow movie theater light style chaser animation."""
+ for j in range(256):
+ for q in range(3):
+ for i in range(0, strip.num_pixels(), 3):
+ strip.set_pixel_color(i+q, wheel((i+j) % 255))
+ strip.show()
+ time.sleep(wait_ms/1000.0)
+ for i in range(0, strip.num_pixels(), 3):
+ strip.set_pixel_color(i+q, 0)
+
+
+class Main(NeoBehaviour):
+
+ def onStart(self):
+ # Do an endless loop with some default ixel test patterns
+ while True:
+ colorWipe(*(255, 0, 0)) # Red wipe
+ colorWipe(*(0, 255, 0)) # Blue wipe
+ colorWipe(*(0, 0, 255)) # Green wipe
+
+ theaterChase(*(127, 127, 127)) # White theater chase
+ theaterChase(*(127, 0, 0)) # Red theater chase
+ theaterChase(*( 0, 0, 127)) # Blue theater chase
+
+ rainbow()
+ rainbowCycle()
+ theaterChaseRainbow() \ No newline at end of file