日常の進捗

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

Mod: Generative Design / P_2_1_1_01 + P_2_1_1_02 + P_2_1_1_03

f:id:takawo:20180107192828p:plain

コード

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

boolean savePDF = false;

int strokecap = ROUND;
int randomseed = (int) random(10000);

int gridSize;

color c1, c2, c3;

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

void draw() {
  if (savePDF) {
    beginRecord(PDF, timestamp() + ".pdf");
    colorMode(HSB, 360, 100, 100, 100);
  }

  randomSeed(randomseed);
  float hue = random(360);
  c1 = color(hue, 80, 100);
  c2 = color((hue+120)%360, 80, 100);
  c3 = color((hue+240)%360, 80, 100);
  background(0, 0, 100);
  noFill();
  strokeCap(strokecap);

  int tileCountY = height / gridSize;
  int tileCountX = width / gridSize;

  for (int j = 0; j < tileCountY; j++) {
    for (int i = 0; i < tileCountX; i++) {
      int posX = (int)map(i, 0, tileCountX, 0, width);
      int posY = (int)map(j, 0, tileCountY, 0, height);
      int n = (int)random(0, 4);
      if (n == 0) {
        strokeWeight(mouseX/30);
        stroke(c1);
        line(posX, posY, posX + gridSize, posY + gridSize);
      }
      if (n == 1) {
        strokeWeight(mouseY/30);
        stroke(c2);
        line(posX, posY + gridSize, posX + gridSize, posY);
      }
      if (n == 2) {
        strokeWeight((mouseX + mouseY)/60);
        stroke(c3);
        point(posX + gridSize/2, posY + gridSize/2);
      }
    }
  }

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

void mousePressed() {
  float hue = random(360);
  c1 = color(hue, 80, 100);
  c2 = color((hue+120)%360, 80, 100);
  c3 = color((hue+240)%360, 80, 100);
  randomseed = (int) random(10000);
}

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

  if (key == '1') strokecap = ROUND;
  if (key == '2') strokecap = SQUARE;
  if (key == '3') strokecap = PROJECT;
}

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

リファレンス