読者です 読者をやめる 読者になる 読者になる

Daily Creative Coding

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

Truchetタイル

/**
* truchet tiles
*
* @author aa_debdeb
* @date 2017/01/19
*/

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

void mousePressed(){

  int tileSize = 25;
  float borderSize = random(0, tileSize / 2);
  color bgColor = color(random(255), random(255), random(255));
  color skColor = color(random(255), random(255), random(255));

  PGraphics[] tiles;
  
  tiles = new PGraphics[2];
  tiles[0] = createGraphics(tileSize, tileSize);
  tiles[0].beginDraw();
  tiles[0].background(bgColor);
  tiles[0].stroke(skColor);
  tiles[0].strokeWeight(borderSize);
  tiles[0].noFill();
  tiles[0].arc(0, 0, tileSize, tileSize, 0, HALF_PI);
  tiles[0].arc(tileSize, tileSize, tileSize, tileSize, HALF_PI * 2, HALF_PI * 3);
  tiles[0].endDraw();
  tiles[1] = createGraphics(tileSize, tileSize);  
  tiles[1].beginDraw();
  tiles[1].background(bgColor);
  tiles[1].stroke(skColor);
  tiles[1].strokeWeight(borderSize);
  tiles[1].noFill();
  tiles[1].arc(tileSize, 0, tileSize, tileSize, HALF_PI, HALF_PI * 2);
  tiles[1].arc(0, tileSize, tileSize, tileSize, HALF_PI * 3, HALF_PI * 4);
  tiles[1].endDraw();

  float prob = float(mouseX + mouseY) / (width + height);
  for(int w = 0; w < width; w += tileSize){
    for(int h = 0; h < height; h += tileSize){
      if(random(1) < prob){
        image(tiles[0], w, h);
      } else {
        image(tiles[1], w, h);
      }
    }
  }
}

void draw(){

}
f:id:aa_debdeb:20170115192923j:plain