Daily Creative Coding

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

脈動するTruchetタイル

/**
* pulsatile truchet tile
*
* @author aa_debdeb
* @date 2017/01/20
*/

int tileSize = 25;
int tileNum = 20;
int[][] types;

color bgColor = color(255, 255, 255);
color skColor1 = color(69, 189, 207);
color skColor2 = color(247, 248, 218);

float time = 0;

void setup(){
  size(500, 500);
  types = new int[tileNum][tileNum];
  for(int x = 0; x < tileNum; x++){
    for(int y = 0; y < tileNum; y++){
      types[x][y] = random(1) < 0.5? 0: 1;
    }
  }
}

void draw(){
  
  time += map(sin(frameCount * 0.01), -1, 1, 0.00, 0.1);
  
  float v = map(sin(time), -1, 1, -1, 1);
  float borderSize = map(v, -1, 1, tileSize / 6.0, tileSize / 3.0);
  
  PGraphics[] tiles;
  
  tiles = new PGraphics[2];
  tiles[0] = createGraphics(tileSize, tileSize);
  tiles[0].beginDraw();
  tiles[0].background(bgColor);
  tiles[0].noFill();
  tiles[0].stroke(skColor1);
  tiles[0].strokeWeight(borderSize);
  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].stroke(skColor2);
  tiles[0].strokeWeight(borderSize / 2.0);
  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].noFill();
  tiles[1].stroke(skColor1);
  tiles[1].strokeWeight(borderSize);
  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].stroke(skColor2);
  tiles[1].strokeWeight(borderSize / 2.0);
  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();

  for(int x = 0; x < tileNum; x++){
    for(int y = 0; y < tileNum; y++){
        image(tiles[types[x][y]], x * tileSize, y * tileSize);
    }
  }
}
f:id:aa_debdeb:20170115194211j:plain