日常の進捗

主に自分のための,行為とその習慣化の記録

Mod: Generative Design / P_2_1_2_03

f:id:takawo:20180111013034g:plain

コード

import processing.pdf.*;
import java.util.Calendar;

boolean savePDF;

int actRandomSeed = (int) random(100000);
float tileCount = 20;
color moduleColor;
int moduleAlpha = 70;
int max_distance = 500;


void setup() {
  size(960, 540, P3D);
  blendMode(ADD);
  colorMode(HSB, 360, 100, 100, 100);
  moduleColor = color(random(360), 50, 50);
}

void draw() {
  if (savePDF) {
    beginRecord(PDF, timestamp() + ".pdf");
    colorMode(HSB, 360, 100, 100, 100);
  }
  background((hue(moduleColor)+90)%360,50,30);
  randomSeed(actRandomSeed);

  strokeWeight(3);
  stroke(moduleColor, moduleAlpha);
  noFill();

  translate(width/2, height/2);
  float theta = map(sin(frameCount*0.01),-1,1,PI/4,-PI/4);
  rotateY(theta);

  for (int gridY = -height/2; gridY < height/2; gridY += 25) {
    for (int gridX = -width/2; gridX < width/2; gridX += 25) {
      float dist = dist(mouseX-width/2, mouseY-height/2, gridX, gridY);
      float diameter = 10 - dist / max_distance * 20;
      pushMatrix();
      translate(gridX, gridY, diameter*5);
      rotateX((gridX+dist) * 0.01);
      rotateY((gridY+dist) * 0.035);
      //rotateZ(frameCount * 0.01);
      rotateX(gridX * 0.1);
      box(diameter*0.5,diameter*0.5,diameter*3);
      popMatrix();
    }
  }

  if (savePDF) {
    endRecord();
    savePDF = false;
  }
}

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

void keyReleased() {
  if (key == 's' || key == 'S') saveFrame(timestamp()+"_##.png");
  if (key == 'p' || key == 'P') savePDF = true;
}

String timestamp() {
  Calendar now = Calendar.getInstance();
  return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now);
}

リファレンス