xxxxxxxxxx
34
class Shapes{
constructor(){
this.angle=0;
this.i=0;
this.colors=["rgb(226,200,126)","rgb(239,165,83)","rgb(236,143,99)","rgb(239,119,110)"]; //array storing colors used as an argument for fill
}
Rectangle(){
translate(width/2,height/2); //shifts the origin to the center of the canvas
rectMode(CENTER);
//for loop to decrease the size of squares
for (let x=width; x>=0; x-=20){
fill(int(random(0,130)));
if (mouseIsPressed){
fill(this.colors[this.i]);
this.i=int(random(this.colors.length));
}
rotate(this.angle);
rect(0,0,x,x);
fill(int(random(150,255)));
if (mouseIsPressed){
fill(this.colors[this.i]);
this.i=int(random(this.colors.length)); //stores a random value from the colors array
}
rotate(45);
rect(0,0,x+20,x+20);
this.angle+=1;
}
}
}