Mod: Generative Design / P_2_1_3_01
randomで設定した方向に同心円が伸びる(中心が進行方向に移動する)部分のオフセットの書き方が面白かった.
コード
import processing.pdf.*; import java.util.Calendar; boolean savePDF = false; int actRandomSeed = (int) random(100000); int tileCount = 10; float tileWidth, tileHeight; color bg; color c; void setup() { size(800, 800); colorMode(HSB, 360, 100, 100, 100); tileWidth = width / tileCount; tileHeight = height / tileCount; bg = color(random(360), random(100), random(50)); c = color((hue(bg)+180)%360, random(80, 100), random(80, 100)); } void draw() { randomSeed(actRandomSeed); background(bg); noFill(); stroke(c); translate(width/tileCount/2, height/tileCount/2); for (int j = 0; j < tileCount; j++) { for (int i = 0; i < tileCount; i++) { float x = width / tileCount * i; float y = height / tileCount * j; float nx = x; float ny = y; int circleCount = (int) map(mouseX, 0, width, 1, 10)+1; float endSize = map(mouseX, 0, width, tileWidth/2, 0); float endOffset = map(mouseY, 0, height, 0, (tileWidth-endSize)/2); pushMatrix(); translate(x, y); int toggle = (int) random(0, 4); if (toggle == 0) rotate(-HALF_PI); if (toggle == 1) rotate(0); if (toggle == 2) rotate(HALF_PI); if (toggle == 3) rotate(PI); for (int n = 0; n < circleCount; n++) { float diameter = map(n, 0, circleCount-1, tileWidth, endSize); float offset = map(n, 0, circleCount-1, 0, endOffset); ellipse(offset, 0, diameter, diameter); } popMatrix(); } } } void mousePressed() { actRandomSeed = (int) random(100000); bg = color(random(360), random(100), random(50,100)); c = color((hue(bg)+180)%360, random(80, 100), random(80, 100)); } 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); }