-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmultiwall_glider.py
executable file
·164 lines (109 loc) · 4.4 KB
/
multiwall_glider.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import acabsl
import time
import math
from functools import partial
acabsl.update()
WALLS = 2
LINES = 6
COLS = 8
DIM = (WALLS, COLS, LINES)
acabsl.update()
def fill(dimensions, color, ftime, draw = True):
walls, cols, lines = dimensions
r, g, b = color
for w in range(walls):
for col in range(cols):
for l in range(lines):
acabsl.send(col, l, r, g, b, ftime, w)
if draw:
acabsl.update()
time.sleep(ftime)
def vline(dimensions, col, color, ftime, draw = True):
walls, cols, lines = dimensions
pixels = []
for l in range(lines):
pixels.append((0, l, color))
pattern(dimensions, col, 0, color, ftime, pixels, draw)
def hline(dimensions, line, color, ftime, draw = True):
walls, cols, lines = dimensions
pixels = []
for c in range(cols * walls):
pixels.append((c, 0, color))
pattern(dimensions, 0, line, color, ftime, pixels, draw)
def hpscan(dim, direction, bgcolor, delay, ftime, pat, cl = True):
walls, cols, lines = dim
all_cols = range(-1 * cols, 1 + cols * walls)
rev = 0 > direction
d = -1 if rev else 1
for col in reversed(all_cols) if rev else all_cols:
if cl:
fill(dim, bgcolor, 0, False)
pat(dimensions=dim, x=col, ftime=ftime, draw=False)
acabsl.update()
time.sleep(ftime + delay)
def hlscan(dimensions, direction, fgcolor, bgcolor, delay, ftime, cl = False):
walls, cols, lines = dimensions
rev = 0 > direction
d = -1 if rev else 1
for col in reversed(range(cols * walls)) if rev else range(cols * walls):
if cl:
fill(dimensions, bgcolor, ftime, False)
vline(dimensions, max(-1, col + d), fgcolor, ftime, False)
vline(dimensions, col, bgcolor, ftime, False)
acabsl.update()
time.sleep(ftime + delay)
def vlscan(dimensions, direction, fgcolor, bgcolor, delay, ftime, cl = False):
walls, cols, lines = dimensions
rev = 0 > direction
d = -1 if rev else 1
for line in reversed(range(lines)) if rev else range(lines):
if cl:
fill(dimensions, bgcolor, ftime, False)
hline(dimensions, max(-1, line + d), fgcolor, ftime, False)
hline(dimensions, line, bgcolor, ftime, False)
acabsl.update()
time.sleep(ftime + delay)
def lifeform(dimensions, x, y, color, ftime, draw = True):
pixels = [ (0, 2, color), (1, 2, color), (2, 2, color), \
(2, 1, color), (1, 0, color) ]
return pattern(dimensions, x, y, color, ftime, pixels, draw = True)
def pattern(dimensions, x, y, color, ftime, pixels, draw = True):
walls, cols, lines = dimensions
def map_pixel(dimensions, x, y, pixel):
walls, cols, lines = dimensions
px, py, pcolor = pixel
return int((x + px) / cols), (x + px) % cols, y + py, pcolor
for p in pixels:
w, c, l, (r, g, b) = map_pixel(dimensions, x, y, p)
if w>-1 and c>-1 and l>-1 and w<walls and c<cols and l<lines:
acabsl.send(c, l, r, g, b, ftime, w)
if draw:
acabsl.update()
time.sleep(ftime)
while True:
fill(DIM, (0, 0, 0), 0)
hlscan(DIM, 1, (255, 0, 0), (0, 255, 0), 0.1, 0)
lifeform(DIM, 1, 2, (255, 0, 0), 1)
fill(DIM, (0, 0, 0), 1)
vlscan(DIM, 1, (255, 0, 0), (0, 0, 255), 0.2, 0)
vlscan(DIM, -1, (0, 255, 0), (0, 0, 0), 0.2, 0)
hpscan(DIM, 1, (0, 0, 0), 0.1, 0, partial(lifeform, y=2, color=(255, 255, 0)))
fill(DIM, (0, 0, 255), 3)
fill(DIM, (0, 255, 255), 2)
fill(DIM, (0, 255, 0), 1)
hlscan(DIM, 1, (255, 0, 0), (0, 255, 0), 0.1, 0)
hlscan(DIM, -1, (255, 0, 0), (0, 128, 128), 0.1, 0)
hlscan(DIM, 1, (255, 0, 0), (64, 0, 128), 0.1, 0)
hlscan(DIM, 1, (255, 0, 0), (0, 0, 0), 0.2, 0.3)
fill(DIM, (0, 255, 0), 3)
fill(DIM, (0, 0, 0), 3)
hlscan(DIM, 1, (255, 0, 0), (0, 0, 0), 0, 0.5)
hlscan(DIM, -1, (255, 0, 0), (0, 255, 0), 0, 0.5, True)
fill(DIM, (0, 0, 0), 5)
hpscan(DIM, 1, (255, 0, 0), 0.1, 0, partial(lifeform, y=2, color=(255, 255, 0)))
hpscan(DIM, 1, (0, 0, 0), 0.1, 0, partial(lifeform, y=1, color=(0, 255, 0)))
hpscan(DIM, 1, (0, 0, 255), 0.1, 0, partial(lifeform, y=3, color=(255, 255, 0)))
hpscan(DIM, 1, (0, 0, 0), 0.1, 0, partial(lifeform, y=2, color=(255, 255, 0)))
fill(DIM, (0, 0, 0), 5)