-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathcode.js
More file actions
43 lines (36 loc) · 949 Bytes
/
code.js
File metadata and controls
43 lines (36 loc) · 949 Bytes
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
let osc, delay, env;
function setup() {
let cnv = createCanvas(400, 400);
background(220);
textAlign(CENTER);
textSize(13);
text('click and drag mouse', width/2, 150);
osc = new p5.Oscillator('sawtooth');
osc.amp(0.74);
env = new p5.Envelope(0.01);
delay = new p5.Delay(0.12, 0.7);
osc.disconnect();
osc.connect(env);
env.disconnect();
env.connect(delay);
cnv.mousePressed(oscStart);
cnv.mouseReleased(oscStop);
cnv.mouseOut(oscStop);
describe('Click and release or hold, to play a square wave with delay effect.');
}
function oscStart() {
background(0, 255, 255);
text('release to hear delay', width/2, 150);
osc.start();
env.triggerAttack();
}
function oscStop() {
background(220);
text('click and drag mouse', width/2, 150);
env.triggerRelease();
}
function draw() {
osc.freq(map(mouseY, height, 0, 440, 880))
let dtime = map(mouseX, 0, width, 0.1, 0.5);
delay.delayTime(dtime);
}