ColorWall Construction

My code fills the window with a pattern of colorful squares of decreasing size in each new row over and over again, until the size of the squares become minimal. Here are some images generated by changing the starting size, rate of change, or colors of the squares:

Screen Shot 2015-11-02 at 12.54.33 PM

Screen Shot 2015-11-02 at 1.02.40 PM

Screen Shot 2015-11-02 at 12.56.05 PM

Screen Shot 2015-11-02 at 12.58.48 PM

And here is my main code:

Square mySquare1;



float y = 0;
float x= 0;
float d= 120;
int count=0;
int red = 0;
int green =0; 
int blue = 0;

void setup(){
  size(900,750);
  background(255);
  }


void draw(){
    if (count==0)
    { red = 121;
      green = 30;
      blue = 157;
    }
    
    if (count==1)
    {red = 255;
     green = 194;
     blue = 62;
    }
    
    if (count==2)
    { red = 255;
      green = 62;
      blue = 168;
    }
    
    strokeWeight(3);
    stroke(red, green, blue);
    
  mySquare1=new Square(x, y, d);
  mySquare1.render();
  x+=d+5;
  if (x>=width){x=0; y+=d+5; d-=2;
  if (y>=height){y=0;}}
  count+=1;
  if(count==3){count=0;}
  
  
}

And the code of my class:

class Square {
  float xPos;
  float yPos;
  float diam;


Square(float x, float y, float d){
  xPos = x;
  yPos= y;
  diam = d;
  
}

void render() {
 
  rect(xPos, yPos, diam, diam);
 
}

 

Leave a Reply