-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMosaicTest.js
executable file
·364 lines (281 loc) · 9.52 KB
/
MosaicTest.js
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
var img, imgdigi, img2, imgdigi2, mapp, rov; //images
var button; //start button
var kp = 0; //chooses between mosaics
var selec; //subselection from mouse click
//vars for trig motion:
var angle1 = 0;
var scalar = 7;
var z1
var counturchin, countfish, countcrab,countlophelia_dead,countsponge,countlophelia_live,countanemone,countseastar,countcallogorgia,countmussel,countparamuricea,counttubeworms, countbrittlestar; //counted values of pixels ->now freq
var sRatio; //canvas height : image height, scaling ratio
//var oscR, oscG, oscB ; //3 oscillators
var mapon; // 1=start screen, 0=other
var windowwidth, windowheight; //var for sub window w,h
var urchin,fish,crab,lophelia_dead,sponge,lophelia_live,anemone,seastar,callogorgia,mussel,paramuricea,tubeworms,brittlestar
function preload() {
img = loadImage("assets/mosaicH12010.png"); //load mosaic
imgdigi = loadImage("assets/mosaicH12010d.png"); //load digitization
img2 = loadImage("assets/mosaicH1geo2010.png"); //load mosaic2
imgdigi2 = loadImage("assets/mosaicH1geo2010d.png"); //load digitization2ß
mapp = loadImage("assets/map.png");
rov = loadImage("assets/rov.png")
crabSound = loadSound('assets/crab.wav')
lophdSound = loadSound('assets/lophelia_dead.wav')
lophlSound = loadSound('assets/lophelia_live.wav')
paraSound = loadSound('assets/paramuricea.wav')
spongeSound = loadSound('assets/sponge.wav')
tubeSound = loadSound('assets/tubeworm.wav')
urchinSound = loadSound('assets/urchin.wav')
fishSound = loadSound('assets/fish.wav')
anemoneSound = loadSound('assets/anemone.wav')
seastarSound = loadSound('assets/seastar.wav')
calloSound = loadSound('assets/callogorgia.wav')
musselSound = loadSound('assets/mussels.wav')
britSound = loadSound('assets/brittlestar.wav')
}
function setup() {
mapon = 1
createCanvas(750,550);
frameRate(60);
background(0);
image(mapp, 0, 0, width, height)
button = createButton('Mosaic H1');
button.position(19, 19);
button.mousePressed(bPress);
crabSound.loop()
crabSound.setVolume(0)
lophdSound.loop()
lophdSound.setVolume(0)
lophlSound.loop()
lophlSound.setVolume(0)
paraSound.loop()
paraSound.setVolume(0)
spongeSound.loop()
spongeSound.setVolume(0)
tubeSound.loop()
tubeSound.setVolume(0)
urchinSound.loop()
urchinSound.setVolume(0)
fishSound.loop()
fishSound.setVolume(0)
anemoneSound.loop()
anemoneSound.setVolume(0)
seastarSound.loop()
seastarSound.setVolume(0)
calloSound.loop()
calloSound.setVolume(0)
musselSound.loop()
musselSound.setVolume(0)
britSound.loop()
britSound.setVolume(0)
/*
oscR = new p5.Oscillator();
oscR.setType('sine');
oscR.amp(0.01);
oscG = new p5.Oscillator();
oscG.setType('sine');
oscG.amp(0.01);
oscB = new p5.Oscillator();
oscB.setType('sine');
oscB.amp(0.01);
*/
}
function setup2() {
mapon = 0
background(0);
imageMode(CORNER)
sRatio = height/img.height;
image(img,0,0,img.width,img.height,0,0,sRatio*img.width,height);
//oscR.start();
//oscG.start();
//oscB.start();
}
function draw() {
//background(0);
//image(img,0,0,img.width,img.height,0,0,sRatio*img.width,height);
if(mapon == 0) {
windowwidth = width-(sRatio*img.width)
windowheight = height/3
var ang1 = radians(angle1);
var z1 = (scalar * cos(ang1));
imageMode(CORNER);
if (kp == 0){
image(img,mouseX/sRatio-(windowwidth/2),mouseY/sRatio-(windowheight/2),windowwidth+z1,windowheight+z1*(windowheight/windowwidth),img.width*sRatio,0,windowwidth,windowheight);
} else if (kp == 1){
image(img2,mouseX/sRatio-(windowwidth/2),mouseY/sRatio-(windowheight/2),windowwidth+z1,windowheight+z1*(windowheight/windowwidth),img.width*sRatio,0,windowwidth,windowheight);
}
//ROV image overlay
image(rov,0,0,rov.width,rov.height,img.width*sRatio,0,windowwidth,windowheight);
//fill(255,0,0)
//ellipse(5,5,5,5)//recording circle
//rotate(z1/10000);
angle1 += 1; //speed of zoom in effect
//oscR.freq(map(counturchin,0,2500,5000,15000),0.2);
//oscG.freq(map(countfish,0,2500,500,5000),0.2);
//oscB.freq(map(gotB,0,255,60,500));
}
}
function bPress() {
setup2()
}
function updateArray() {
if (kp == 0){
selec = imgdigi.get(mouseX/sRatio-(windowwidth/2),mouseY/sRatio-(windowheight/2),windowwidth,windowheight);
} else if (kp == 1){
selec = imgdigi2.get(mouseX/sRatio-(windowwidth/2),mouseY/sRatio-(windowheight/2),windowwidth,windowheight);
}
selec.loadPixels();
fill(0);
imageMode(CORNER);
image(selec,img.width*sRatio,windowheight);
if (kp == 0){
blend(img,mouseX/sRatio-(windowwidth/2),mouseY/sRatio-(windowheight/2),windowwidth,windowheight,img.width*sRatio,windowheight,windowwidth,windowheight,MULTIPLY);
} else if (kp == 1){
blend(img2,mouseX/sRatio-(windowwidth/2),mouseY/sRatio-(windowheight/2),windowwidth,windowheight,img.width*sRatio,windowheight,windowwidth,windowheight,MULTIPLY);
}
}
function countRed1() {
var urchc = color(1,92,230);
var fishc = color(2,0,0);
var crabc = color(56,168,0);
var lophdc = color(114,178,115);
var spongec = color(115,76,0);
var lophlc = color(151,219,242);
var anemc = color(169,0,230);
var seastarc = color(209,255,115);
var calloc = color(232,190,255);
var musselc = color(251,211,127);
var parac = color(252,170,0);
var tubec = color(253,255,115);
var britc = color(254,0,197);
var counturchin = 0;
var countfish = 0;
var countcrab = 0;
var countlophelia_dead = 0;
var countsponge = 0;
var countlophelia_live = 0;
var countanemone = 0;
var countseastar = 0;
var countcallogorgia = 0;
var countmussel = 0;
var countparamuricea = 0;
var counttubeworms = 0;
var countbrittlestar = 0;
for (var xR = 0; xR < selec.pixels.length; xR = xR + 4) {
if(selec.pixels [xR] == red(urchc)) {
counturchin++;
} else if(selec.pixels [xR] == red(fishc)) {
countfish++;
} else if(selec.pixels [xR] == red(crabc)) {
countcrab++;
} else if(selec.pixels [xR] == red(lophdc)) {
countlophelia_dead++;
} else if(selec.pixels [xR] == red(spongec)) {
countsponge++;
} else if(selec.pixels [xR] == red(lophlc)) {
countlophelia_live++;
} else if(selec.pixels [xR] == red(anemc)) {
countanemone++;
} else if(selec.pixels [xR] == red(seastarc)) {
countseastar++;
} else if(selec.pixels [xR] == red(calloc)) {
countcallogorgia++;
} else if(selec.pixels [xR] == red(musselc)) {
countmussel++;
} else if(selec.pixels [xR] == red(parac)) {
countparamuricea++;
} else if(selec.pixels [xR] == red(tubec)) {
counttubeworms++;
} else if(selec.pixels [xR] == red(britc)) {
countbrittlestar++;
}
}
urchin = new Graph(0,counturchin);
fish = new Graph(1,countfish);
crab = new Graph(2,countcrab);
lophelia_dead = new Graph(3,countlophelia_dead);
sponge = new Graph(4,countsponge);
lophelia_live = new Graph(5,countlophelia_live);
anemone = new Graph(6,countanemone);
seastar = new Graph(7,countseastar);
callogorgia = new Graph(8,countcallogorgia);
mussel = new Graph(9,countmussel);
paramuricea = new Graph(10,countparamuricea);
tubeworms = new Graph(11,counttubeworms);
brittlestar = new Graph(12,countbrittlestar);
fill(0)
rect(img.width*sRatio, windowheight*2,windowwidth,windowheight)//cover rects w/ black
//fill(255)
//rect(img.width*sRatio, windowheight*2,map(counturchin, 0, windowheight*windowwidth, 0, windowwidth),windowheight/13)
//rect(img.width*sRatio, windowheight*2+windowheight/13,map(countfish, 0, windowheight*windowwidth, 0, windowwidth),windowheight/13)
fill(urchc);
urchin.display();
fill(fishc);
fish.display();
fill(crabc);
crab.display();
fill(lophdc);
lophelia_dead.display();
fill(spongec);
sponge.display();
fill(lophlc);
lophelia_live.display();
fill(anemc);
anemone.display();
fill(seastarc);
seastar.display();
fill(calloc);
callogorgia.display();
fill(musselc);
mussel.display();
fill(parac);
paramuricea.display();
fill(tubec);
tubeworms.display();
fill(britc);
brittlestar.display();
crabSound.setVolume(map(countcrab,0,2500,0,1),1);
lophdSound.setVolume(map(countlophelia_dead,0,2500,0,0.15),1);
lophlSound.setVolume(map(countlophelia_live,0,2500,0,0.25),1);
paraSound.setVolume(map(countparamuricea,0,2500,0,0.5),1);
spongeSound.setVolume(map(countsponge,0,2500,0,0.5),1);
tubeSound.setVolume(map(counttubeworms,0,2500,0,0.3),1);
urchinSound.setVolume(map(counturchin,0,2500,0,0.7),1);
fishSound.setVolume(map(countfish,0,2500,0,0.7),1);
anemoneSound.setVolume(map(countanemone,0,2500,0,2),1);
seastarSound.setVolume(map(countseastar,0,2500,0,0.7),1);
calloSound.setVolume(map(countcallogorgia,0,2500,0,0.4),1);
musselSound.setVolume(map(countmussel,0,2500,0,0.7),1);
britSound.setVolume(map(countbrittlestar,0,2500,0,0.8),1);
}
function Graph(number, count) {
this.number = number;
this.count = count;
print(count); //see actual pixel counts of each organism in console
this.display = function(){
this.count = count;
rect(img.width*sRatio, windowheight*2+this.number*windowheight/13,map(count, 0, windowheight*windowwidth, 0, windowwidth),windowheight/13)
}
}
function keyPressed() {
if (kp == 0){
kp = 1;
} else {
kp = 0;
}
switchMosaic();
updateArray();
countRed1();
}
function switchMosaic() {
imageMode(CORNER);
if (kp == 0){
image(img,0,0,img.width,img.height,0,0,sRatio*img.width,height);
} else if (kp == 1){
image(img2,0,0,img.width,img.height,0,0,sRatio*img.width,height);
}
}
function mousePressed(){
updateArray();
countRed1();
};