-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbubbles.py
executable file
·101 lines (81 loc) · 2.29 KB
/
bubbles.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
#!/usr/bin/python3
from launchpad import *
from random import *
from common import *
import colorsys
import time
lp = LaunchpadMiniMk3(pickPortInteractive())
grid = None
pressedButtons = []
fireworks = []
class Firework:
def __init__(self, x, y):
self.x = x
self.y = y
self.radius = 0
self.expansionRate = 0.01
self.maxRadius = 20
self.alive = True
def release(self):
pass
def update(self):
self.radius += self.expansionRate
class Grid:
def __init__(self):
self.gridArr = [[0 for j in range(0, GRID_HEIGHT)] for i in range(0, GRID_WIDTH)]
def getCellValue(self, x, y):
return self.gridArr[x][y]
def setCellValue(self, x, y, val):
self.gridArr[x][y] = val
def printGridInt(self):
for j in range(0, GRID_HEIGHT):
print(["%04d" % int(i) for i in self.gridArr[j]])
print("\n")
def update(self):
for f in fireworks:
f.update()
def draw(self):
pass
def buttonRelease(msg):
x = int(msg.note % 10) - 1
y = int(msg.note / 10) - 1
for i in range(0, len(pressedButtons)):
if (pressedButtons[i][0] == x and pressedButtons[i][1] == y):
del(pressedButtons[i])
break
print("BUTTON RELEASE", msg)
def controlChange(msg):
print("CONTROL CHANGE", msg)
def buttonPress(msg):
x = int(msg.note % 10) - 1
y = int(msg.note / 10) - 1
pressedButtons.append((x, y))
print("BUTTON PRESS x %d, y %d" % (x, y))
def processButtonPresses():
global grid
for b in pressedButtons:
currVal = grid.getCellValue(b[0], b[1])
newVal = currVal + 1000
grid.setCellValue(b[0], b[1], newVal)
def main():
global grid
# Register launchpad callbacks
lp.onButtonPressCb = buttonPress
lp.onButtonReleaseCb = buttonRelease
lp.onControlChangeCb = controlChange
lp.ClearGrid()
lp.SelectLayout(LAYOUT_PROGRAMMER)
grid = Grid()
running = True
while(running):
try:
lp.Poll()
processButtonPresses()
grid.update()
grid.draw()
time.sleep(0.04)
except KeyboardInterrupt:
running = False
lp.SelectLayout(LAYOUT_CUSTOM1)
if __name__ == "__main__":
main()