aboutsummaryrefslogtreecommitdiff
path: root/NeoRuntime/builtin/twinkle/script.py
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 /NeoRuntime/builtin/twinkle/script.py
parent629503252de51f3a95ae3dd19ef837012eea9fc2 (diff)
downloadLuxcena-Neo-98bb009777de51ef8900155cda05c92cc1cb3ab1.tar.gz
Luxcena-Neo-98bb009777de51ef8900155cda05c92cc1cb3ab1.zip
Add some modes
Diffstat (limited to 'NeoRuntime/builtin/twinkle/script.py')
-rw-r--r--NeoRuntime/builtin/twinkle/script.py30
1 files changed, 30 insertions, 0 deletions
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()
+