aboutsummaryrefslogtreecommitdiff
path: root/NeoRuntime
diff options
context:
space:
mode:
authorjakob.stendahl <jakob.stendahl@infomedia.dk>2022-12-05 15:36:49 +0100
committerJakob Stendahl <jakob.stendahl@outlook.com>2022-12-05 15:36:49 +0100
commitdd8d828414583d6993774240d76c2c2782627ef6 (patch)
tree35cac7a132f8fbab4babea2c7f71218ea1e0939a /NeoRuntime
parentb1b8b9605d804793f557c92e2d7b1f659d8c99f0 (diff)
downloadLuxcena-Neo-dd8d828414583d6993774240d76c2c2782627ef6.tar.gz
Luxcena-Neo-dd8d828414583d6993774240d76c2c2782627ef6.zip
Do some design improvements
Diffstat (limited to 'NeoRuntime')
-rw-r--r--NeoRuntime/Runtime/luxcena_neo/strip.py10
-rw-r--r--NeoRuntime/Runtime/neo_runtime.py6
-rw-r--r--NeoRuntime/builtin/rainbow/script.py38
3 files changed, 51 insertions, 3 deletions
diff --git a/NeoRuntime/Runtime/luxcena_neo/strip.py b/NeoRuntime/Runtime/luxcena_neo/strip.py
index b1b90ba..b0165c9 100644
--- a/NeoRuntime/Runtime/luxcena_neo/strip.py
+++ b/NeoRuntime/Runtime/luxcena_neo/strip.py
@@ -121,7 +121,9 @@ class Strip:
def _set_brightness(self, value):
self.__actual_brightness = value
- self.strip.setBrightness(value)
+ # Logarithmic curve, to try to make the brightness controll feel more natural.
+ v = int(10**((value-1)/41.11))
+ self.strip.setBrightness(v)
self.show()
def show(self):
@@ -147,7 +149,11 @@ class Strip:
def set_pixel_color_XY(self, x, y, *color):
"""Set LED at position n to the provided 24-bit color value (in RGB order).
"""
- self.set_pixel_color(self.pixelMatrix.get(x, y), *color)
+ try:
+ pixel = self.pixelMatrix.get(x, y)
+ self.set_pixel_color(self.pixelMatrix.get(x, y), *color)
+ except IndexError as e:
+ print(f"Pixel outside matrix cannot be set ({x}, {y})")
def set_segment_color(self, segment, *color):
"""Set a whole segment to the provided red, green and blue color.
diff --git a/NeoRuntime/Runtime/neo_runtime.py b/NeoRuntime/Runtime/neo_runtime.py
index 7733a4b..c577444 100644
--- a/NeoRuntime/Runtime/neo_runtime.py
+++ b/NeoRuntime/Runtime/neo_runtime.py
@@ -204,7 +204,11 @@ class NeoRuntime:
def __module_loop(self):
- self.__module_entry_instance.on_start()
+ try:
+ self.__module_entry_instance.on_start()
+ except Exception as e:
+ traceback.print_exc()
+ sys.exit(1)
self.__module_last_tick = time.perf_counter()
self.__module_last_second = time.perf_counter()
diff --git a/NeoRuntime/builtin/rainbow/script.py b/NeoRuntime/builtin/rainbow/script.py
new file mode 100644
index 0000000..292ef97
--- /dev/null
+++ b/NeoRuntime/builtin/rainbow/script.py
@@ -0,0 +1,38 @@
+from luxcena_neo import NeoBehaviour, utils, FloatVariable, BooleanVariable
+from time import perf_counter
+
+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(FloatVariable("speed", 0.95, min_val=0, max_val=1, step=0.01))
+ self.declare(BooleanVariable("Uniform", True))
+
+ def on_start(self):
+ """ Execute when mode is selected. """
+ self.j = 0
+ self.i = 0
+ self.last_inst = perf_counter()
+
+ def each_tick(self):
+ """Draw rainbow that fades across all pixels at once."""
+ if (perf_counter() - self.last_inst) > (1.01-self.var.Speed):
+ self.last_inst = perf_counter()
+ self.j += 1
+ if self.j >= 256: self.j = 0
+ for i in range(strip.num_pixels()):
+ if self.var["Uniform"]:
+ strip.set_pixel_color(i, wheel(int((i * 256 // strip.num_pixels()) + self.j) & 255))
+ else:
+ strip.set_pixel_color(i, wheel((i+self.j) & 255))
+ strip.show()