-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhyperventilate.py
141 lines (114 loc) · 3.49 KB
/
hyperventilate.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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 02 14:39:39 2015
@author: William Herrera
IMPORTANT: run as administrator
Color breathing package for G20aj series PC
"""
import light_acpi as la
from time import sleep
def make_rgb(cred, cgreen, cblue):
"""
make rgb for components
"""
redval = int(round(cred))
greenval = int(round(cgreen))
blueval = int(round(cblue))
ret = int(redval * 0x10000 + greenval * 0x100 + blueval)
if ret < 0:
ret = 0
if ret > 0x00ffffff:
ret = 0x00ffffff
return ret
def split_rgb(color):
"""
split rgb into red, green, blue
"""
red = (color & 0xff0000) / 0x10000
green = (color & 0xff00) / 0x100
blue = color & 0xff
return red, green, blue
def make_ratios(cred, cgreen, cblue):
"""
get ratios of colors
"""
maxcolor = max(cred, cgreen, cblue)
return float(cred)/float(maxcolor), \
float(cgreen)/float(maxcolor), \
float(cblue)/float(maxcolor)
def make_gamut(color):
"""
make a sequence of 256 colors
"""
sequence256 = []
cred, cgreen, cblue = split_rgb(color)
rred, rgreen, rblue = make_ratios(cred, cgreen, cblue)
for step in range(256):
tred = float(step) * rred
tgreen = float(step) * rgreen
tblue = float(step) * rblue
sequence256.append(make_rgb(tred, tgreen, tblue))
return sequence256, sequence256.index(color)
def dim_up_down_up_sequence(gamut, idex, frames):
"""
up color intensity to full
"""
# initial compiled list is size 512
cseq = gamut[idex:] + gamut[::-1] + gamut[0:idex]
# adjust size
reframed = []
ratio = 512.0 / frames
for frameidx in range(frames):
gamut_pos = int(round(frameidx * ratio))
reframed.append(cseq[gamut_pos])
return reframed
def run_color_sequence(lighting, colors, sleepinterval):
"""
run a breathing type change sequence through once
sleepinterval is in seconds or fractions of seconds
"""
for colr in colors:
lighting.set_color(colr)
sleep(sleepinterval)
def continuous_cycle(lighti, startcolor, frames=32, sleepinterval=0.1):
"""
breathe in color saturation
"""
gam, orig_idx = make_gamut(startcolor)
seq = dim_up_down_up_sequence(gam, orig_idx, frames)
while True:
run_color_sequence(lighti, seq, sleepinterval)
def run_triple_sequence(lightlist, colorlist, sleeptime):
"""
do all 3 lights given list of all 3
"""
lli = lightlist[0]
rli = lightlist[1]
bli = lightlist[2]
lcol = colorlist[0]
rcol = colorlist[1]
bcol = colorlist[2]
for idx in range(len(lcol)):
lli.set_color(lcol[idx])
rli.set_color(rcol[idx])
bli.set_color(bcol[idx])
sleep(sleeptime)
def all_cycle(scolors, frames=32, sleepinterval=0.1):
"""
all LED lighting do continuous cycle breathing
"""
# make light and color lists
lights = [la.ASUSLighting(la.DPATH, la.LEFT_VERTICAL), \
la.ASUSLighting(la.DPATH, la.RIGHT_VERTICAL), \
la.ASUSLighting(la.DPATH, la.BASE_HORIZONTAL)]
clists = []
for idx in range(len(lights)):
gam, orig_idx = make_gamut(scolors[idx])
seq = dim_up_down_up_sequence(gam, orig_idx, frames)
clists.append(seq)
while True:
run_triple_sequence(lights, clists, sleepinterval)
if __name__ == '__main__':
SCOL = 0x1111ff
LLIGHT = la.ASUSLighting(la.DPATH, la.LEFT_VERTICAL)
continuous_cycle(LLIGHT, SCOL)