Skip to content
Snippets Groups Projects
Select Git revision
  • 1a6013794693c88b497f7e97ed14122a3b314f16
  • main default protected
  • phhw
  • captouch-threshold
  • t
  • dos
  • test2
  • test
  • slewtest
  • simtest
  • view-think
  • vm-pending
  • media-buf
  • scope
  • passthrough
  • wave
  • vsync
  • dos-main-patch-50543
  • json-error
  • rahix/big-flow3r
  • pippin/media_framework
  • v1.3.0
  • v1.2.0
  • v1.2.0+rc1
  • v1.1.1
  • v1.1.0
  • v1.1.0+rc1
  • v1.0.0
  • v1.0.0+rc6
  • v1.0.0+rc5
  • v1.0.0+rc4
  • v1.0.0+rc3
  • v1.0.0+rc2
  • v1.0.0+rc1
34 results

demo_worms.py

Blame
  • Forked from flow3r / flow3r firmware
    Source project has a limited visibility.
    ledfx.py 1.23 KiB
    import leds, utime, math
    
    
    def col_cor(colors, brightness=1, gamma=1):
        return [
            [int(255 * brightness * math.pow((y / 255.0), gamma)) for y in x]
            for x in colors
        ]
    
    
    def halo(colors):
        used_leds = len(colors)
        colors += [[0, 0, 0]] * (11 - used_leds)
        colors += [colors[used_leds - 1]] + [colors[0]] * 2 + [colors[used_leds - 1]]
        return colors
    
    
    def kitt(
        cycles=100,
        delay=80,
        power=10,
        minimum=0.3,
        rgb=[255, 0, 0],
        spectrum=[],
        halo=False,
    ):
        """
        LED Animation.
        """
        kitt_table = [((-math.cos(math.pi * (x / 10.0))) + 1) / 2.0 for x in range(21)]
        kitt_table = [math.pow(x, power) * (1 - minimum) + minimum for x in kitt_table]
    
        for i in range(cycles):
            j = i % 20
            if j > 10:
                j = 20 - j
            if spectrum == []:
                used_leds = 11
                output = [[int(x * y) for y in rgb] for x in kitt_table[j : (j + 11)]]
            else:
                used_leds = len(spectrum)
                output = [
                    [int(y * kitt_table[j + x]) for y in spectrum[x]]
                    for x in range(used_leds)
                ]
            if halo:
                halo(output)
            leds.set_all(output)
            utime.sleep_ms(delay)
        leds.clear()