日常の進捗

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

Mod: Generative Design / P_2_1_1_04

f:id:takawo:20180108174150p:plain

サンプルコードはSVGファイルをシェイプとして読み込むものだったが極力図形をコードで描いた.タイムアップ.

コード

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

boolean savePDF;
int tileCount = 15;
float tileWidth, tileHeight;
float shapeSize = 50;
float newShapeSize = shapeSize;
float shapeAngle = 0;
float maxDist;

color shapeColor;
int shapeMode = 0;
int fillMode = 0;
int sizeMode = 0;

void setup() {
  size(960, 540);
  colorMode(HSB, 360, 100, 100, 100);
}

void draw() {
  if (savePDF) {
    //beginRecord(PDF, timestamp()+".pdf");
    colorMode(HSB, 360, 100, 100, 100);
  }
  background(0, 0, 100);
  tileWidth = width/float(tileCount);
  tileHeight = height/float(tileCount);
  maxDist = sqrt(sq(width)+sq(height));

  for (float y = 0; y < height; y += tileHeight) {
    for (float x = 0; x < width; x += tileWidth) {
      float posX = x + tileWidth / 2;
      float posY = y + tileHeight / 2;

      float angle = atan2(mouseY - posY, mouseX - posX) + radians(shapeAngle);
      angle += (x + y*width)* 0.001;

      switch(shapeMode) {
      case 0:
        pushMatrix();
        translate(posX, posY);
        rotate(angle);
        strokeWeight(shapeSize/4);
        stroke(0, 0, 0);
        noFill();
        line(0, -shapeSize/2, 0, shapeSize/2);
        popMatrix();
        break;
      case 1:
        pushMatrix();
        translate(posX, posY);
        rotate(angle);
        strokeWeight(1);
        fill(0, 0, 100);
        stroke(0, 0, 0);
        line(0, -shapeSize/2, 0, shapeSize/2);
        line(-shapeSize/4, 0, shapeSize/4, 0);
        ellipse(0, -shapeSize/2, shapeSize/6, shapeSize/6);
        ellipse(0, shapeSize/2, shapeSize/6, shapeSize/6);
        ellipse(-shapeSize/4, 0, shapeSize/6, shapeSize/6);
        ellipse(shapeSize/4, 0, shapeSize/6, shapeSize/6);
        popMatrix();
        break;
      case 2:
        pushMatrix();
        translate(posX, posY);
        rotate(angle);
        noStroke();
        fill(0, 0, 70);
        ellipse(0, 0, shapeSize/2, shapeSize/2);
        fill(0, 0, 0);
        ellipse(0, shapeSize/4, shapeSize/2, shapeSize/2);
        popMatrix();
        break;
      case 3:
        pushMatrix();
        translate(posX, posY);
        rotate (angle);
        pushMatrix();
        rotate(-PI/4);
        noStroke();
        fill(0, 0, 50);
        rect(0, 0, 100, 100);
        popMatrix();

        pushMatrix();
        noStroke();
        fill(0, 0, 0);
        translate(50*sqrt(2), 0);
        quad(0, 0, 50, 50, 25, 0, 50, -50);  
        popMatrix();
        popMatrix();
        break;
      }
    }
  }

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

void keyPressed() {
  if (key == '0') shapeMode = 0;
  if (key == '1') shapeMode = 1;
  if (key == '2') shapeMode = 2;
  if (key == '3') shapeMode = 3;
  if (key == '4') shapeMode = 4;
  if (key == '5') shapeMode = 5;
  if (key == '6') shapeMode = 6;
}


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

リファレンス