xxxxxxxxxx
70
//cowritten with Sean Greavesand Elizabeth Funk
// 09/29/22 Recurse Center
let osc, playing,freq,amp
function setup() {
createCanvas(400, 400);
let cnv = createCanvas(400, 400);
cnv.mousePressed(playOscillator);
osc = new p5.Oscillator('sine');
frameRate(5)
}
function draw() {
//background(220);
translate(width/2,height/2)
let j=int(mouseX)
for (let i =0; i<j; i++){
rotate(2*PI*i/j)
stroke(random(255),random(255),random(255))
fill(random(255),random(255),random(255))
line(random(50),random(50),random(200),0)
}
textSize(22)
text(str("Variegated Haribo"),0,100+random(3))
freq = constrain(map(mouseX, 0, width, 100, 500), 100, 500);
amp = constrain(map(mouseY, height, 0, 0, 1), 0, 1);
text('tap to play', 20, 20);
text('freq: ' + freq, 20, 40);
text('amp: ' + amp, 20, 60);
if (playing) {
// smooth the transitions by 0.1 seconds
osc.freq(freq, 0.1);
osc.amp(amp, 0.1);
}
}function playOscillator() {
// starting an oscillator on a user gesture will enable audio
// in browsers that have a strict autoplay policy.
// See also: userStartAudio();
osc.start();
playing = true;
}
function mouseReleased() {
// ramp amplitude to 0 over 0.5 seconds
osc.amp(0, 0.5);
playing = false;
}
function playOscillator() {
// starting an oscillator on a user gesture will enable audio
// in browsers that have a strict autoplay policy.
// See also: userStartAudio();
osc.start();
playing = true;
}
function mouseReleased() {
// ramp amplitude to 0 over 0.5 seconds
osc.amp(0, 0.5);
playing = false;
}
// variegated haribo
// getting cerebral
// this color wheel
// giving me feels