-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblocks.py
65 lines (56 loc) · 1.69 KB
/
blocks.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
from tkinter import *
import random
import time
from colors import colors
barWidth = 100
class Bar:
def __init__(self, len, width, color):
self.len = len
self.width = width
self.color = color
class Row:
def __init__(self, bars):
self.bars = bars;
def draw(self):
barStrs = []
for bar in self.bars:
barStrs.append("".join(['-' for i in range(0, bar.len)]))
print("|".join(barStrs))
def drawOnCanvas(self, canvas, startingHeight):
xPoint = 0;
for bar in self.bars:
canvas.create_rectangle(xPoint, startingHeight, xPoint+bar.len, startingHeight + bar.width, fill=bar.color)
xPoint += bar.len
canvas.pack()
def createBars(screenSize, numBars, minBarSize, maxBarSize, barWidth):
sizeRemain = screenSize;
bars = []
for i in range(0, 8):
numRemain = numBars - i - 1;
smallestPossible = sizeRemain - (numRemain * maxBarSize)
largestPossible = sizeRemain - (numRemain * minBarSize)
barLength = random.randint(max(smallestPossible, minBarSize), min(maxBarSize, largestPossible))
sizeRemain -= barLength
randColor = colors[random.randint(0, len(colors) - 1)]
bars.append(Bar(barLength, barWidth, randColor))
return bars
def genRows(numRows):
rows =[]
for i in range(0,numRows):
bars = createBars(2560, 8, 250, 600, barWidth);
rows.append(Row(bars))
return rows;
def moveRows(rows):
rows.pop()
bars = createBars(2560, 8, 100, 450, barWidth);
rows.insert(0, Row(bars))
return rows
root = Tk()
w = Canvas(root, width=2560, height=1000)
def draw():
startingHeight = 0;
for row in genRows(10):
row.drawOnCanvas(startingHeight, w)
startingHeight += barWidth
w.after(500, draw) #120BPM
draw()