つよくなりたいなあ

地に足をつけず世界を生きぬくブログです

Generative Design: グリッドと整列

/*
 * 2018/08/26
 * Grid
 */
int tileCount = 40;
int actStrokeCap = ROUND;
int actRandomSeed = (int)random(10000);

int gridSize;
color c1, c2, c3;

void setup() {
  size(640, 640);
  colorMode(HSB, 360, 100, 100, 100);
  gridSize = height/15;
}

void draw() {
  background(360);
  smooth();
  noFill();
  strokeCap(actStrokeCap);
  randomSeed(actRandomSeed);

  float hue = random(360);
  c1 = color(hue, 80, 100);
  c2 = color((hue+120)%360, 80, 100);
  c2 = color((hue+240)%360, 60, 100);


  for (int  gridY = 0; gridY < tileCount; gridY++) {
    for (int gridX = 0; gridX < tileCount; gridX++) {

      int posX = width/tileCount*gridX;
      int posY = height/tileCount*gridY;

      int toggle = (int)random(0, 2);

      if (toggle == 0) {
        strokeWeight(mouseX/20);
        stroke(c1);
        line(posX, posY, posX+width/tileCount, posY+height/tileCount);
      }
      if (toggle == 1) {
        strokeWeight(mouseY/20);
        stroke(c2);
        line(posX, posY+width/tileCount, posX+height/tileCount, posY);
      }
    }
  }
}

void keyReleased() {
  if (key == 's') {
    saveFrame("grid-##.png");
  }
  if (key == '1') {
    actStrokeCap = ROUND;
  }
  if (key == '2') {
    actStrokeCap = SQUARE;
  }
  if (key == '3') {
    actStrokeCap = PROJECT;
  }
}

f:id:heyassy:20180826034636p:plain