日常の進捗

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

Mod: Generative Design / P_2_0_02 + P_2_0_03

f:id:takawo:20180107163355p:plain

コード

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

boolean recordPDF = false;

void setup() {
  size(960, 540, FX2D);
  colorMode(HSB, 360, 100, 100, 100);
  blendMode(ADD);
  background(0, 0, 0);
}

void draw() {
  translate(width/2, height/2);
  rotate(frameCount*0.01);
  int circleResolution = (int) map(mouseY, 0, height, 3, 10);
  float radius = map(mouseX-width/2, 0, width, 0, sqrt(sq(width/2)+sq(height/2)));
  float angle = TWO_PI / (float)circleResolution;

  strokeWeight(2);
  stroke(frameCount%360, 80, 100, 15);
  noFill();

  if (mousePressed) {
    beginShape();
    for (int i = 0; i <= circleResolution; i++) {
      float x = cos(angle * i) * radius;
      float y = sin(angle * i) * radius;
      vertex(x, y);
    }
    endShape();
  }
}

void keyReleased() {
  if (key == DELETE || key == BACKSPACE) background(0, 0, 0);
  if (key=='s' || key=='S') saveFrame(timestamp()+"_##.png");

  if (key =='r' || key =='R') {
    if (recordPDF == false) {
      beginRecord(PDF, timestamp()+".pdf");
      colorMode(HSB, 360, 100, 100, 100);
      println("recording started");
      recordPDF = true;
      smooth();
      noFill();
      background(0, 0, 0);
    } else {
      println("recording stopped");
      endRecord();
      recordPDF = false;
      background(0, 0, 0);
    }
  }
}


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

リファレンス