xxxxxxxxxx
42
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 mousePressed() {
let tempPostIt = new postIt(mouseX, mouseY);
allPostIts.push(tempPostIt);
}
class postIt {
constructor(posX, posY) {
this._posX = posX;
this._posY = posY;
this._size = random(50, 100);
this.color = color(random(255), random(255), random(255));
this.angle = random(-45,45);
}
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();
}
}