xxxxxxxxxx
52
let allPostIts = [];
function setup() {
createCanvas(500, 500);
}
function draw() {
background(220);
if (allPostIts.length > 0) {
for (let i = 0; i < allPostIts.length; i++) {
allPostIts[i].display();
}
}
}
function mouseDragged() {
let tempPostIt = new postIt(mouseX, mouseY);
allPostIts.push(tempPostIt);
}
class postIt {
constructor(posX, posY) {
this._posX = posX;
this._posY = posY;
this._size = random(25, 50);
this.color = color(random(255), random(255), random(255));
this.angle = random(-45, 45);
this.timer = 100;
this.speed = random(5,20);
this.randomSpin = random(-2,2);
}
display() {
fill(this.color);
noStroke();
rectMode(CENTER);
push();
translate(this._posX, this._posY);
rotate(radians(this.angle));
rect(0, 0, this._size, this._size);
pop();
this.timer--;
if (this.timer <= 0) {
this._posY+=this.speed;
this.angle+= this.randomSpin;
}
}
}