xxxxxxxxxx
71
let angle = 0;
let angleV = 0.05;
let yoyos = [];
let colors;
function setup() {
createCanvas(windowWidth, windowHeight);
colors = [
color(255, 0, 0),
color(0, 255, 0),
color(0, 0, 255),
color(255),
color(128),
color(0, 255, 255),
color(255, 0, 255),
color(255, 255, 0),
color(102, 68, 34),
color(255, 128, 0),
color(255, 128, 128),
color(128, 0, 128)
];
for (let i = 0; i < 170; i++) {
yoyos.push(new Yoyo(12, 2, random(20, 50), random(0.0035, 0.009), random(colors)));
}
}
function draw() {
background(20, 54);
for (let y of yoyos) {
y.update();
y.render();
}
}
class Yoyo {
constructor(x, y, r, angleV, colour) {
this.x = x;
this.y = y;
this.r = r;
this.angle = 0;
this.angleV = angleV;
this.color = colour;
}
update() {
angle += angleV;
}
render() {
translate(this.x, this.y);
fill(this.color);
stroke(this.color);
let y = map(sin(this.angle), -1, 1, -700, 700);
push();
strokeWeight(2);
line(0, 0, 0, y);
circle(0, y, this.r);
this.angle += this.angleV;
pop();
}
}