-
Notifications
You must be signed in to change notification settings - Fork 0
/
LunarSoundRect.pyde
73 lines (65 loc) · 2.27 KB
/
LunarSoundRect.pyde
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
add_library('sound')
img = None
imgNumbers = [] #array of pixel sounds
noteToPlay = [0] * 5
file = [] #list of sound files
posx = (0, 128, 256, 384, 512) #position of "key notes"
playSound = [1] * 5
def setup():
global index,img, imgNumbers,trigger
size(1280, 720) #main window
background(255)
#add our sound files to file array
for i in range(5):
file.append(SoundFile(this, "%d.wav" % (i+1)))
img = loadImage("lunar.png")
#print(img.width,img.height)
#exit()
for i in range(img.width * img.height): #go through pixels
c = img.pixels[i] # color of that pixel
x = map(c, color(0), color(255), 0, 4) #map color to sounds
print(c,x)
imgNumbers.append(floor(x))
# each pixel = a float from 0 to 5, match available sounds
#print(len(imgNumbers)) #number of pixels in our image
#print(imgNumbers[60:70],file)
index = 0
trigger = millis()
noStroke()
def draw():
global trigger, index,img,file
translate(325,45)
image(img, 0, 0) #draw the image
noStroke()
fill(0,0,0,0)
stroke(0,255,0)
strokeWeight(3)
rect((index%63)*10,(int(index/63)%63)*10,10,10)
noStroke()
if (millis() > trigger): #every time
noStroke()
#fill(255) #notebox
#rect(0, 640, 630, 50)
#take five pixels
noteToPlay[0] = imgNumbers[index]
noteToPlay[1] = imgNumbers[index + 1]
noteToPlay[2] = imgNumbers[index + 2]
noteToPlay[3] = imgNumbers[index + 3]
noteToPlay[4] = imgNumbers[index + 4]
for i in range(4):
if noteToPlay[i] != noteToPlay[i + 1]: #when the notes differ
note = noteToPlay[i]
print(noteToPlay[i],noteToPlay[i + 1],index)
file[note].play()
#fill(int(random(255)), int(random(255)), int(random(255)))
#rect(posx[i], 640, 128, 50)
playSound[i] = int(random(0,2))
noStroke()
fill(0,255,0,0)
stroke(0,255,0)
strokeWeight(10)
rect((index%63)*10,(int(index/63)%63)*10,10,10)
index = (index + 1) % len(imgNumbers)
print(index,i)
if trigger < millis(): #a time between 400-800ms
trigger = millis() +int(random(400, 800)) #400