aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakob.stendahl <jakob.stendahl@infomedia.dk>2022-12-06 11:37:46 +0100
committerJakob Stendahl <jakob.stendahl@outlook.com>2022-12-06 11:37:46 +0100
commit98bb009777de51ef8900155cda05c92cc1cb3ab1 (patch)
tree1b866d1ac3bcba187a397f99b396162f337a6d23
parent629503252de51f3a95ae3dd19ef837012eea9fc2 (diff)
downloadLuxcena-Neo-98bb009777de51ef8900155cda05c92cc1cb3ab1.tar.gz
Luxcena-Neo-98bb009777de51ef8900155cda05c92cc1cb3ab1.zip
Add some modes
-rw-r--r--NeoRuntime/builtin/fade_all/script.py26
-rw-r--r--NeoRuntime/builtin/running/script.py27
-rw-r--r--NeoRuntime/builtin/strobe/script.py34
-rw-r--r--NeoRuntime/builtin/twinkle/script.py30
4 files changed, 117 insertions, 0 deletions
diff --git a/NeoRuntime/builtin/fade_all/script.py b/NeoRuntime/builtin/fade_all/script.py
new file mode 100644
index 0000000..ee07324
--- /dev/null
+++ b/NeoRuntime/builtin/fade_all/script.py
@@ -0,0 +1,26 @@
+from luxcena_neo import NeoBehaviour, FloatVariable
+from time import perf_counter
+
+class Main(NeoBehaviour):
+
+ def declare_variables(self):
+ self.declare(FloatVariable("speed", 0.99, min_val=0.5, max_val=1, step=0.001))
+
+ def on_start(self):
+ self.intensity = 0
+ self.color = 0
+ self.inc = 1
+ self.last_inst = perf_counter()
+
+ def each_tick(self):
+ if (perf_counter() - self.last_inst) > (1.001-self.var.speed):
+ self.intensity += self.inc
+ if self.intensity % 256 == 0: self.inc *= -1
+ if self.intensity <= 0: self.color = (self.color + 1) % 3
+ set_all(*[self.intensity if i == self.color else 0 for i in range(3)])
+ self.last_inst = perf_counter()
+
+def set_all(*color):
+ for i in range(strip.num_pixels()):
+ strip.set_pixel_color(i, *color)
+ strip.show()
diff --git a/NeoRuntime/builtin/running/script.py b/NeoRuntime/builtin/running/script.py
new file mode 100644
index 0000000..24147ce
--- /dev/null
+++ b/NeoRuntime/builtin/running/script.py
@@ -0,0 +1,27 @@
+from luxcena_neo import NeoBehaviour, ColorVariable, utils
+from time import perf_counter
+from math import sin
+
+class Main(NeoBehaviour):
+
+ def declare_variables(self):
+ self.declare(ColorVariable("color", "#ffffff", on_change=self.change_color))
+
+ def change_color(self, color):
+ self.red, self.green, self.blue = utils.hex_to_rgb(color)
+
+ def on_start(self):
+ self.red, self.green, self.blue = 255, 255, 255
+ self.position = 0
+ self.last_inst = perf_counter()
+
+ def each_tick(self):
+ if (perf_counter() - self.last_inst) > (0.07):
+ self.position = (self.position + 1) % (strip.num_pixels() * 2)
+ for i in range(strip.num_pixels()):
+ level = int(sin(i+self.position) * 127 + 128);
+ strip.set_pixel_color(i,int(((sin(i+self.position) * 127 + 128)/255)*self.red),
+ int(((sin(i+self.position) * 127 + 128)/255)*self.green),
+ int(((sin(i+self.position) * 127 + 128)/255)*self.blue));
+ self.last_inst = perf_counter()
+ \ No newline at end of file
diff --git a/NeoRuntime/builtin/strobe/script.py b/NeoRuntime/builtin/strobe/script.py
new file mode 100644
index 0000000..cd5bffd
--- /dev/null
+++ b/NeoRuntime/builtin/strobe/script.py
@@ -0,0 +1,34 @@
+from luxcena_neo import NeoBehaviour, FloatVariable, IntegerVariable, ColorVariable, BooleanVariable
+from time import perf_counter
+
+class Main(NeoBehaviour):
+
+ def declare_variables(self):
+ self.declare(FloatVariable("delay", 0.07, min_val=0.01, max_val=0.5, step=0.01))
+ self.declare(IntegerVariable("pause", 20, min_val=1, max_val=60))
+ self.declare(IntegerVariable("strobe count", 10, min_val=1, max_val=100))
+ self.declare(ColorVariable("color", "#fafafa"))
+
+ def on_start(self):
+ self.strobe_enabled = False
+ self.strobe_on = False
+ self.strobe_c = 0
+ self.last_inst = perf_counter()
+
+ def each_tick(self):
+ if (perf_counter() - self.last_inst) > (self.var["delay"].value if self.strobe_enabled else self.var["pause"].value):
+ if not self.strobe_enabled: self.strobe_enabled = True
+ self.strobe_c += 1
+ set_all(self.var["color"].value if self.strobe_on else 0)
+ self.strobe_on = not self.strobe_on
+ if self.strobe_c >= (self.var["strobe count"].value * 2):
+ self.strobe_c = 0
+ self.strobe_enabled = False
+ self.strobe_on = False
+ set_all(0)
+ self.last_inst = perf_counter()
+
+def set_all(*color):
+ for i in range(strip.num_pixels()):
+ strip.set_pixel_color(i, *color)
+ strip.show() \ No newline at end of file
diff --git a/NeoRuntime/builtin/twinkle/script.py b/NeoRuntime/builtin/twinkle/script.py
new file mode 100644
index 0000000..86ccc7f
--- /dev/null
+++ b/NeoRuntime/builtin/twinkle/script.py
@@ -0,0 +1,30 @@
+from luxcena_neo import NeoBehaviour, FloatVariable, IntegerVariable, ColorVariable, BooleanVariable, utils
+from time import perf_counter
+from random import randint
+
+class Main(NeoBehaviour):
+
+ def declare_variables(self):
+ self.declare(FloatVariable("speed", 0.41, min_val=0.01, max_val=1, step=0.01))
+ self.declare(IntegerVariable("count", 2, min_val=1, max_val=strip.num_pixels()))
+ self.declare(BooleanVariable("random colors", False))
+ self.declare(ColorVariable("color", "#ffffff"))
+
+ def on_start(self):
+ self.pixel_on_count = 0
+ self.last_inst = perf_counter()
+
+ def each_tick(self):
+ if (perf_counter() - self.last_inst) > (1.01 - self.var.speed):
+ self.pixel_on_count += 1
+ if self.pixel_on_count >= self.var.count:
+ strip.blank()
+ self.pixel_on_count = 0
+ else:
+ c = utils.hex_to_rgb(self.var.color)
+ if self.var["random colors"].value:
+ c = (randint(0,255), randint(0,255), randint(0,255))
+ strip.set_pixel_color(randint(0,strip.num_pixels()), *c)
+ strip.show()
+ self.last_inst = perf_counter()
+