-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlights_wave.py
More file actions
63 lines (46 loc) · 1.51 KB
/
lights_wave.py
File metadata and controls
63 lines (46 loc) · 1.51 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Just a test script.
import socket
class LightControl(object):
"""Example client for the light server."""
def __init__(self, nick, host='valot.party', port=9909):
self.host = host
self.port = port
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.nick = nick.encode('utf-8')
def set(self, lights):
"""Lights should be a list of tuples like (id, r, g, b) with the
RGB values in a [0..1] range."""
packet = bytearray([
1, # API version
0, # Nick tag
])
packet.extend(bytearray([ord(char) for char in self.nick]))
packet.append(0) # end nick tag
# [0..1] -> [0..255]
to_ubyte = lambda val: int(max(min(val, 1.0), 0.0) * 255)
for light in lights:
packet.extend([
1,
light[0],
0, # Effect type
to_ubyte(light[1]), # r
to_ubyte(light[2]), # g
to_ubyte(light[3]), # b
])
self.sock.sendto(packet, (self.host, self.port))
control = LightControl('airzero', 'localhost')
import math
import time
hue = 0
t = 0
def red(n, t):
return 0.5 + math.sin(n + t) * 0.5
def green(n, t):
return 0.5 + math.sin(n + 1.0 + t) * 0.5
def blue(n, t):
return 0.5 + math.sin(n + 2.0 + t) * 0.5
while True:
control.set([
(n, red(n, t), green(n, t), blue(n, t)) for n in range(0, 24)])
t += 0.1
time.sleep(0.05)