-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotate_grid.py
59 lines (40 loc) · 1.59 KB
/
rotate_grid.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
from cv2 import rectangle
from dorothy import Dorothy
import numpy as np
dot = Dorothy()
class MySketch:
def __init__(self):
dot.start_loop(self.setup, self.draw)
def setup(self):
print("setup")
#Play file from your computer
file_path = "../audio/disco.wav"
dot.music.start_file_stream(file_path)
#Pick or just stream from your computer
#On MacOSX I use Blackhole and Multioutput device to pump audio to here, and to listen in speakers as well
# print(sd.query_devices())
#dot.music.start_device_stream(3)
def draw(self):
dot.background((22, 208, 165))
size = 40
border = 10
grid = 5
x_offset = (dot.width - ((size+border)*grid)) //2
y_offset = (dot.height - ((size+border)*grid)) //2
for i in range(grid):
for j in range(grid):
#Where to draw the shape?
x = i * (size+border) + x_offset
y = j * (size+border) + y_offset
#get a new canvas
new_canvas = dot.get_layer()
#Draw to it
top_left = (x,y)
bottom_right = (x+size, y+size)
rectangle(new_canvas, top_left, bottom_right, (77, 72, 79), -1)
theta = dot.music.amplitude() * 15 * 2 * np.pi
origin = (x+size/2, y+size/2)
new_canvas = dot.rotate(new_canvas, theta, origin)
#push it back onto layer stack
dot.draw_layer(new_canvas)
MySketch()