xxxxxxxxxx
51
class Oscillator {
constructor(offset) {
this.angle = createVector();
let angleOffset = map(offset, 0, 10, 0, PI/24);
this.velocity = createVector(0.05 + angleOffset, 0.05 - angleOffset);
this.amplitude = createVector(width/4, height/4);
let noiseOffset = map(offset, 0, 10, 0, 2);
this.t = noiseOffset;
}
oscillate() {
this.angle.add(this.velocity);
this.t += 0.01;
}
display() {
// if (mouseIsPressed) {
// this.amplitude.x = 200;
// this.amplitude.y = 200;
// } else {
// this.amplitude.x = 100;
// this.amplitude.y = 100;
// }
// what happens if you assign amplitude to sound levels?
// this.amplitude.x = mic.getLevel() * 100;
let x = cos(this.angle.x) * this.amplitude.x
let y = sin(this.angle.y) * this.amplitude.y
push();
translate(width / 2, height / 2);
//stroke(255);
//strokeWeight(2);
let r = 255 * noise(this.t + 10);
let g = 255 * noise(this.t + 150);
let b = 255 * noise(this.t + 200);
fill(r, g, b);
line(0, 0, x, y);
noStroke();
ellipse(x, y, 32, 32);
pop();
}
}