aboutsummaryrefslogtreecommitdiff
path: root/NeoRuntime/builtin/static/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/static/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/static/script.py')
-rw-r--r--NeoRuntime/builtin/static/script.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/NeoRuntime/builtin/static/script.py b/NeoRuntime/builtin/static/script.py
new file mode 100644
index 0000000..0f07304
--- /dev/null
+++ b/NeoRuntime/builtin/static/script.py
@@ -0,0 +1,38 @@
+from luxcena_neo import NeoBehaviour, VariableType, utils
+import time
+
+class Main(NeoBehaviour):
+
+ def declare_variables(self):
+ self.vars.declare("color", "#fafafa", VariableType.COLOR, self.set_color)
+
+ def on_start(self):
+ print(f"Script started, color: {self.vars.color}")
+ self.set_color(self.vars.color)
+ strip.power_on = True
+ # self.current_color = self.vars.color
+
+ def set_color(self, value):
+ print(f"Color var changed: {value}")
+ # transition_color(self.current_color, value, 1)
+
+def lerp(a, b, u):
+ return (1 - u) * a + u * b
+
+def transition_color(start_color, end_color, duration):
+ start_color = utils.hex_to_rgb(start_color)
+ end_color = utils.hex_to_rgb(end_color)
+ interval = 10
+ steps = duration / interval
+ step_u = 1.0 / steps
+ u = 0
+
+ while u < 1:
+ r = round(lerp(start_color[0], end_color[0], u))
+ g = round(lerp(start_color[1], end_color[1], u))
+ b = round(lerp(start_color[2], end_color[2], u))
+ for i in len(strip.LED_COUNT):
+ strip.set_pixel_color(i, (r, g, b))
+ strip.show()
+
+ time.sleep(interval / 100) \ No newline at end of file