frackingToasters
Weekly challenge in a discord group for old OS.
function preload() {
toaster = loadImage("/assets/toaster.gif");
}
let t_Array = [];
let nToaster = 25;
let s;
function setup() {
createCanvas(windowWidth, windowHeight);
for (let i = 0; i < nToaster; i++) {
t_Array.push(new Cylon(i + 1));
}
s = 20;
}
function draw() {
background(0);
translate(width / 2, height / 2);
for (let i = 0; i < nToaster; i++) {
t_Array[i].move();
t_Array[i].display();
}
}
class Cylon {
constructor(p) {
this.x = random(-width / 2, width / 2 + 500);
this.y = -height / 2 + (p * (height + 400)) / nToaster;
}
move() {
this.x -= 0.5;
this.y += 0.5;
if (this.y > height + 200) {
this.x = random(-width / 2, width / 2 + 200);
this.y = -height / 2 - 200;
}
}
display() {
image(toaster, this.x, this.y, toaster.width / s, toaster.height / s);
}
}
function mousePressed() {
t_Array = [];
for (let i = 0; i < nToaster; i++) {
t_Array.push(new Cylon(i));
}
}