Daily Creative Coding

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

編みこみ斜め格子

/**
* knitted skew lattice
*
* @author aa_debdeb
* @date 2016/08/15
*/

float step = 20;
float stepNum = 25;
float border = 5; 

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 x = 0; x < stepNum; x++){
    for(int y = 0; y < stepNum; y++){
      if(random(1) < 0.5){
        pushMatrix();
        translate(x * step, y * step);
        fill((x + y) % 2 == 0 ? c1 : c2);
        drawLine1();
        fill((x + y) % 2 == 1 ? c1 : c2);
        drawLine2();
        popMatrix();
      } else {
        pushMatrix();
        translate(x * step, y * step);
        fill((x + y) % 2 == 1 ? c1 : c2);
        drawLine2();
        fill((x + y) % 2 == 0 ? c1 : c2);
        drawLine1();
        popMatrix();
      } 
    }
  }
}

void drawLine1(){
  beginShape();
  vertex(0, 0);
  vertex(0, border);
  vertex(step - border, step);
  vertex(step, step);
  vertex(step, step - border);
  vertex(border, 0);
  endShape(CLOSE);
}

void drawLine2(){
  beginShape();
  vertex(step, 0);
  vertex(step - border, 0);
  vertex(0, step - border);
  vertex(0, step);
  vertex(border, step);
  vertex(step, border);
  endShape();
}
f:id:aa_debdeb:20160808203123j:plain