Daily Creative Coding

元「30 min. Processing」。毎日、Creative Codingします。

編みこみ格子

/**
* knitted lattice 
*
* @author aa_debdeb
* @date 2016/08/14
*/

float step = 20;
float border = 10;

void setup(){
  size(500, 500);
  mousePressed();
}

void draw(){

}

void mousePressed(){
  background(random(255), random(255), random(255));
  color c1 = color(random(255), random(255), random(255));
  color c2 = color(random(255), random(255), random(255));

  noStroke();
  for(int w = 0; w < width; w += step){
    for(int h = 0; h < height; h += step){
      if(random(1) < 0.5){
        fill(c1);
        rect(w, h + (step - border) / 2, step, border);
        fill(c2);
        rect(w + (step - border) / 2, h, border, step);
      } else {
        fill(c2);
        rect(w + (step - border) / 2, h, border, step);        
        fill(c1);
        rect(w, h + (step - border) / 2, step, border);
      } 
    }
  }
}
f:id:aa_debdeb:20160807225858j:plain