-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_initialistion.py
executable file
·116 lines (99 loc) · 3.27 KB
/
basic_initialistion.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
#!/usr/bin/python
from time import sleep
from blinkt import set_pixel, show
def rotate(list,shift):
return list[0 + shift:] + list[:0 + shift]
def show_state(state):
for pixel in range(8):
set_pixel(pixel, *state[pixel])
show()
def cycle(times,states,sleep_time=1,gap=None):
if gap is None:
gap = states / 8
for count in range(times):
state = states[0::gap]
show_state(state)
print("{0:4d} : red = {1:3.2f} | green = {2:3.2f} | blue = {3:3.2f}"
.format(count, *state[0]))
sleep(sleep_time)
states = rotate(states,1)
return state
def chase(state, max_count=40, delay=1, style=1, bounce=7):
direction = -1
if style == 2:
direction = 1
count = 0
while count <= max_count:
count += 1
show_state(state)
state = rotate(state, direction)
if style == 3 and (count % bounce) == 0:
direction = 0 - direction
print("count = {0:3d} : mod = {1:1d} : dir = {2:3d}".format(
count, count % bounce, direction))
sleep(delay)
return state
def turn_off():
state = set_two_tone((0,0,0), split=8)
show_state(state)
return state
def set_two_tone(colour_a, colour_b=(0, 0, 0), split=1):
state=[]
for pixel in range(split):
state.append(colour_a)
for pixel in range(split,8):
state.append(colour_b)
return state
def kit_chase(colour, iterations=100, fade=6, delay=0.1, background=(0,0,0)):
current_pixel = 0
decrement = 100.0** (1 / float(fade))
level = [0.0 for x in range(8)]
step = -1
for _ in range(iterations):
if current_pixel % 7 == 0:
step = 0 - step
level = [max(x / decrement, 0) for x in level]
level[current_pixel] = 1.0
for pixel in range(8):
set_pixel(pixel, *colour, brightness=level[pixel])
show()
print("{0:d} : {1:1.2f} {2:1.2f} {3:1.2f} {4:1.2f} {5:1.2f} {6:1.2f} {7:1.2f} {8:1.2f}".format(current_pixel, *level))
current_pixel += step
sleep(delay)
red = ([x*2.125 for x in range(120)] +
[255 - (x*2.125) for x in range(120)] +
[0 for x in range(120)])
green = rotate(red, 120)
blue = rotate(green, 120)
red_pixel=(255, 0, 0)
grn_pixel=(0, 255, 0)
blu_pixel=(0, 0, 255)
ppl_pixel=(95, 0, 160)
blk_pixel=(0, 0, 0)
degrees = zip(red, green, blue)
colour_swatch = []
for pixel in range(8):
loc = pixel * 45
colour_swatch.append(degrees[loc])
state = cycle(360, degrees, .1, 20)
sleep(5)
turn_off()
state = chase(colour_swatch, 60, 0.1)
state = chase(colour_swatch, 60, 0.1, 2)
state = chase(colour_swatch, 60, 0.1, 3)
sleep(2)
state = set_two_tone(red_pixel)
state = chase(state, 63, 0.1, 3)
state = set_two_tone(grn_pixel)
state = chase(state, 63, 0.1, 3)
state = set_two_tone(blu_pixel, red_pixel)
state = chase(state, 63, 0.1, 3)
for build in range(2,8):
state = set_two_tone(ppl_pixel, split=build)
state = chase(state, (8-build)*4, 0.1, 3, 8-build)
for decline in range(2,8):
state = set_two_tone(blk_pixel, ppl_pixel, split=decline)
state = chase(state, (8-decline)*8, 0.1, 3, 8-decline)
state = kit_chase(red_pixel, iterations=120, fade=6, delay=0.1, background=(0,0,0))
sleep(3)
state = turn_off()