aboutsummaryrefslogtreecommitdiff
path: root/NeoRuntime/builtin/twinkle/script.py
blob: 86ccc7f69b045a96be3f6dd3e1cb8186c5aea570 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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()