-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch3.js
98 lines (77 loc) · 2.24 KB
/
sketch3.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
//~ var fingers;
//~ function setup() {
//~ createCanvas(560,320);
//~ // specify multiple formats for different browsers
//~ fingers = createVideo(['assets/small.mov',
//~ 'assets/small.webm']);
//~ fingers.loop();
//~ fingers.hide();
//~ noStroke();
//~ fill(0);
//~ }
//~ function draw() {
//~ background(255);
//~ fingers.loadPixels();
//~ var stepSize = round(constrain(mouseX / 8, 6, 32));
//~ for (var y=0; y<height; y+=stepSize) {
//~ for (var x=0; x<width; x+=stepSize) {
//~ var i = y * width + x;
//~ var darkness = (255 - fingers.pixels[i*4]) / 255;
//~ var radius = stepSize * darkness;
//~ ellipse(x, y, radius, radius);
//~ }
//~ }
//~ }
var capture, sound, amplitude, cnv, mic;
function preload () {
// we have included both an .ogg file and an .mp3 file
soundFormats('ogg', 'mp3');
// if mp3 is not supported by this browser,
// loadSound will load the ogg file
// we have included with our sketch
//~ sound = loadSound('assets/ylvis-both-choruses.mp3');
}
function setup() {
cnv = createCanvas(320, 240);
//~ createCanvas(320, 240);
sound = loadSound('assets/ylvis-both-choruses.mp3');
amplitude = new p5.Amplitude();
amplitude.setInput(sound);
cnv.mouseClicked(togglePlay);
capture = createCapture(VIDEO);
capture.size(320,240);
capture.hide();
mic = new p5.AudioIn();
mic.start();
//~ noStroke();
//~ fill(0);
//~ audio.loop();
//~ audio.hide();
}
function draw() {
background(255);
image(capture, 0, 0, 320,240);
filter('POSTERIZE',2);
//~ filter('POSTERIZE',randNum(2,127));
//~ filter('POSTERIZE',getAmplitudeModifier(2,18));
filter('BLUR',getMicrophoneModifier(1,12));
}
function randNum(min,max) {
return Math.floor(Math.random() * max) + min;
}
function getAmplitudeModifier(min,max) {
return Math.floor(amplitude.getLevel() * max) + min;
}
function getMicrophoneModifier(min,max) {
var micL = mic.getLevel();
document.querySelector('#micLevel').innerHTML = Math.floor(micL * max) + min;
return Math.floor(micL * max) + min;
}
// fade sound if mouse is over canvas
function togglePlay() {
if (sound.isPlaying()) {
sound.pause();
} else {
sound.loop();
}
}