xxxxxxxxxx
57
let r;
let angle = 0.1;
let colorAngle = 10;
let waveColor;
let colorR;
let colorG;
let colorB;
let waves = [];
function setup() {
createCanvas(600, 400);
for (let i = 0; i < 5; i++) {
waves[i] = new Wave(random(20, 40), random(100, 600), random(TWO_PI));
}
colorAngleR = random(255);
colorAngleG = random(255);
colorAngleB = random(255);
}
//change color on mouse press
function mouseClicked() {
colorAngleR += random(60);
colorAngleG += random(60);
colorAngleB += random(60);
}
function draw() {
background(8, 1);
//translate(width / 2, height / 2); // set origin point to center
//fill(252, 238, 33);
colorAngleR += random(0.001, 0.01);
colorAngleG += random(0.001, 0.01);
colorAngleB += random(0.001, 0.01);
//console.log("Color RGB: " + colorR + " " + colorG + " " + colorB);
for (let x = 0; x < width; x += 2) {
let y = 0;
for (let wave of waves) {
y += wave.evaluate(x);
}
colorR = map(sin(colorAngleR), -1, 1, 0, 255);
colorG = map(sin(colorAngleG), -1, 1, 0, 255);
colorB = map(sin(colorAngleB), -1, 1, 0, 255);
noStroke();
fill(colorR, colorG, colorB, 10);
ellipse(x, y + height / 2, 5);
}
for (let wave of waves) {
wave.update();
}
}