-
Notifications
You must be signed in to change notification settings - Fork 0
/
led_visualizers.py
37 lines (31 loc) · 1.19 KB
/
led_visualizers.py
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
31
32
33
34
35
36
37
import time
import colorsys
import random
import math
################################################################
# Music Visualisers
################################################################
def sound_original(pixels, melspectrum):
for i in range(len(pixels)//2):
value = None
if melspectrum[i] > 0.6:
value = (255,0,0)
elif melspectrum[i] > 0.4:
value = (0,0,255)
elif melspectrum[i] > 0.2:
value = (0,255,0)
if value is not None:
pixels[len(pixels)//2+i] = value
pixels[len(pixels)//2-i] = value
pixels.show()
def sound_rgb(pixels, melspectrum):
for i in range(len(pixels)//2):
r, g, b = colorsys.hls_to_rgb(max(0, 1-melspectrum[i]),0.5,1)
bright = min(1, max(0, (melspectrum[i]-0.1)/8))
pixels[len(pixels)//2+i] = (int(r*255*bright), int(g*255*bright), int(b*255*bright))
pixels[len(pixels)//2-i] = (int(r*255*bright), int(g*255*bright), int(b*255*bright))
pixels.show()
def sound_pulse(pixels, melspectrum, color):
for i in range(len(pixels)):
pixels[i] = color
pixels.set_brightness(min(1, sum(melspectrum)/len(pixels)))