見出し画像

ProcessingでGenerative art #53

Code

int actRandomSeed = 0;
int tileCount = 30;
int rectSizeW;
int rectSizeH;
float maxDist;

void setup() {
  size(750, 750);
  pixelDensity(2);
  strokeWeight(0.5);
  noStroke();
  colorMode(HSB, 360, 100, 100, 100);
  rectSizeW = width/tileCount;
  rectSizeH= height/tileCount;
  maxDist = sqrt(sq(width) + sq(height));
}

void draw() {
  background(0);
  randomSeed(actRandomSeed);
  drawTile();
}

void drawTile() {
  for (int gridY = 0; gridY < tileCount; gridY++) {
    for (int gridX = 0; gridX < tileCount; gridX++) {
      int posX = width/tileCount * gridX;
      int posY = height/tileCount * gridY;
      float shiftRange = map(dist(mouseX, mouseY, posX + rectSizeW, posY + rectSizeH), 0, maxDist, 0, 20);
      float shiftX1 = random(-shiftRange, shiftRange);
      float shiftY1 = random(-shiftRange, shiftRange);
      float shiftX2 = random(-shiftRange, shiftRange);
      float shiftY2 = random(-shiftRange, shiftRange);
      float shiftX3 = random(-shiftRange, shiftRange);
      float shiftY3 = random(-shiftRange, shiftRange);
      float shiftX4 = random(-shiftRange, shiftRange);
      float shiftY4 = random(-shiftRange, shiftRange);
      float colShift = map(dist(mouseX, mouseY, posX + rectSizeW, posY + rectSizeH), 0, maxDist, 0, 200);
      fill(180 + random(-colShift, colShift), 98, 92);
      beginShape();
      vertex(posX+shiftX1, posY+shiftY1);
      vertex(posX+rectSizeW+shiftX2, posY+shiftY2);
      vertex(posX+rectSizeW+shiftX3, posY+rectSizeH+shiftY3);
      vertex(posX+shiftX4, posY+rectSizeH+shiftY4);
      endShape(CLOSE);
    }
  }
}

void mousePressed() {
  actRandomSeed = (int)random(10000);
}

void keyPressed(){
  if(key == 's')saveFrame("####.png");
}

参考: 『Generative Design-Processingで切り拓く、デザインの新たな地平』

応援してくださる方!いつでもサポート受け付けてます!