根茎図のカタログ
実家に帰るとあまりやることがないので今年の振り返りをしながらWebの改修のための作業などをする予定.
コード(カタログ版)
import processing.pdf.*; import java.util.Calendar; boolean savePDF = false; float len = 35; int row = 6; int col = 5; int grid; void setup() { //settings(); blendMode(ADD); colorMode(HSB, 360, 100, 100, 100); grid = width / col; } void settings() { int dpi=72; float width_mm=210; float height_mm=297; int width_px=int(width_mm*0.03937*dpi); int height_px=int(height_mm*0.03937*dpi); size(width_px, height_px, P2D); } void draw() { if (savePDF) beginRecord(PDF, timestamp()+".pdf"); colorMode(HSB, 360, 100, 100); // write some code...start background(150, 80, 30); for (float y = 0; y < height; y += height/row) { for (float x = 0; x < width; x += width/col) { pushMatrix(); translate(x+grid/2, y+grid/2); rotate(random(TWO_PI)); tree(int(random(3, 6)), len); popMatrix(); } } noLoop(); // write some code...end if (savePDF) { savePDF = false; endRecord(); } } void tree(int depth, float l) { if (depth > 0) { float n = (int) random(3, 10); for (float angle = 0; angle < 360; angle += 360/n) { float theta = radians(angle)+random(-PI/4, PI/4); pushMatrix(); rotate(theta); stroke(0, 0, 100, 100); noFill(); float sw = map(l, 0, len, 0, 3); strokeWeight(sw); if (random(1) > 0.5) { bezier(0, 0, l/2, l/2, l/2, -l/2, l, 0); } else { bezier(0, 0, l/2, -l/2, l/2, l/2, l, 0); } //line(0, 0, l, 0); noStroke(); fill(0, 0, 100, 100); float d = map(l, 0, len, 0, 5); ellipse(l, 0, d, d); translate(l, 0); rotate(radians(360/n)/2); tree(depth-1, l*0.45); popMatrix(); } } } void mousePressed() { redraw(); } void keyPressed() { 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); }