aboutsummaryrefslogtreecommitdiff
path: root/NeoRuntime/builtin
diff options
context:
space:
mode:
Diffstat (limited to 'NeoRuntime/builtin')
-rw-r--r--NeoRuntime/builtin/fade/script.py28
-rw-r--r--NeoRuntime/builtin/static/script.py17
-rw-r--r--NeoRuntime/builtin/strandtest/script.py74
3 files changed, 119 insertions, 0 deletions
diff --git a/NeoRuntime/builtin/fade/script.py b/NeoRuntime/builtin/fade/script.py
new file mode 100644
index 0000000..8fe902a
--- /dev/null
+++ b/NeoRuntime/builtin/fade/script.py
@@ -0,0 +1,28 @@
+from luxcena_neo import NeoBehaviour, IntegerVariable
+
+def wheel(pos):
+ """Generate rainbow colors across 0-255 positions."""
+ if pos < 85:
+ return (pos * 3, 255 - pos * 3, 0)
+ elif pos < 170:
+ pos -= 85
+ return (255 - pos * 3, 0, pos * 3)
+ else:
+ pos -= 170
+ return (0, pos * 3, 255 - pos * 3)
+
+class Main(NeoBehaviour):
+
+ def declare_variables(self):
+ self.declare(IntegerVariable("speed", 2, min_val=1, max_val=50))
+
+ def on_start(self):
+ """ Execute when mode is selected. """
+ self.i = 0
+
+ def each_tick(self):
+ self.i += self.var.speed
+ if self.i > 255: self.i = 0
+ for i in range(strip.num_pixels()):
+ strip.set_pixel_color(i, wheel(self.i))
+ strip.show()
diff --git a/NeoRuntime/builtin/static/script.py b/NeoRuntime/builtin/static/script.py
new file mode 100644
index 0000000..8916106
--- /dev/null
+++ b/NeoRuntime/builtin/static/script.py
@@ -0,0 +1,17 @@
+from luxcena_neo import NeoBehaviour, ColorVariable, utils
+
+class Main(NeoBehaviour):
+
+ def declare_variables(self):
+ self.declare(ColorVariable("color", "#fafafa", on_change=self.set_color))
+
+ def on_start(self):
+ print("Script started, color: {}".format(self.var.color))
+
+ def set_color(self, value):
+ print("Color var changed: {}".format(value))
+ print(utils.detect_format_convert_color(value))
+ for i in range(strip.LED_COUNT):
+ strip.set_pixel_color(i, value)
+ strip.show()
+
diff --git a/NeoRuntime/builtin/strandtest/script.py b/NeoRuntime/builtin/strandtest/script.py
new file mode 100644
index 0000000..50bac1e
--- /dev/null
+++ b/NeoRuntime/builtin/strandtest/script.py
@@ -0,0 +1,74 @@
+from luxcena_neo import NeoBehaviour, utils
+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 (pos * 3, 255 - pos * 3, 0)
+ elif pos < 170:
+ pos -= 85
+ return (255 - pos * 3, 0, pos * 3)
+ else:
+ pos -= 170
+ return (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(int((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 on_start(self):
+ colorWipe(*(255, 0, 0)) # Red wipe
+ colorWipe(*(0, 255, 0)) # Blue wipe
+ colorWipe(*(0, 0, 255)) # Green wipe
+
+ while True:
+ theaterChase(*(127, 127, 127)) # White theater chase
+ theaterChase(*(127, 0, 0)) # Red theater chase
+ theaterChase(*( 0, 0, 127)) # Blue theater chase
+
+ rainbow()
+ rainbowCycle()
+ theaterChaseRainbow()