Auto Generated Eyesをつくりました
Auto Generated Eyesをつくりました。ジェネレーティブアートです。色と大きさを変化させた目のモチーフを多数並べました。
以下はソースコードです。開発環境はMacBook Air、Processingです。
Eyes.pde
// Eyes import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; final boolean cSAVE_FLG = false; final int cSAVE_NUM = 20; final int cSTART_NUM = 0; final int cDIGIT_NUM = 2; //// For Logo image size //final int cMyWidth = 350; //final int cMyHeight = 350; //final String cFILE_NAME = "Eyes_Logo_"; //// For Featured image size //final int cMyWidth = 600; //final int cMyHeight = 400; //final String cFILE_NAME = "Eyes_Featured_"; //// For Banner image size //final int cMyWidth = 1400; //final int cMyHeight = 400; //final String cFILE_NAME = "Eyes_Banner_"; // For HD final int cMyWidth = 1280; final int cMyHeight = 720; final String cFILE_NAME = "Eyes_"; //// For Full HD //final int cMyWidth = 1920; //final int cMyHeight = 1080; //final String cFILE_NAME = "Eyes_"; //// For Test //final int cMyWidth = 800; //final int cMyHeight = 450; //final String cFILE_NAME = "Eyes_"; final boolean cLOOP_FLG = true; final float cFRAME_RATE = 0.3; final int cCELL_SIZE = 60; final float cEYE_RATIO = 0.8; Eye e; float adjustmentValueX = 0.0; float adjustmentValueY = 0.0; int maxH = 0; int maxV = 0; void settings() { size(cMyWidth, cMyHeight); } void setup() { if (cSAVE_FLG) { noLoop(); } else if (cLOOP_FLG) { frameRate(cFRAME_RATE); } else { noLoop(); } e = new Eye(width / 2, height / 2, int(cCELL_SIZE * cEYE_RATIO)); maxH = int(width / cCELL_SIZE) + 1; maxV = int(height / cCELL_SIZE) + 1; adjustmentValueX = (maxH * cCELL_SIZE - width) / 2; adjustmentValueY = (maxV * cCELL_SIZE - height) / 2; } void draw() { int loopMax = 1; if (cSAVE_FLG) { loopMax = cSAVE_NUM; } for (int i = 0; i < loopMax; i++) { myDraw(); if (cSAVE_FLG) { LocalDateTime utcDateTime = LocalDateTime.now(ZoneId.of("UTC")); DateTimeFormatter dateFrmt = DateTimeFormatter.ofPattern("uuuuMMdd"); DateTimeFormatter timeFrmt = DateTimeFormatter.ofPattern("HHmmss,SSSSSS"); String dateStr = dateFrmt.format(utcDateTime); String timeStr = timeFrmt.format(utcDateTime); save(cFILE_NAME + "#" + nf(cSTART_NUM + i, cDIGIT_NUM) + "_" + dateStr + "T" + timeStr + "Z" + ".png"); } } } void myDraw() { background(random(0, 256)); colorMode(HSB, 360, 100, 100); float hue = 0.0; float lookX = random(width + cCELL_SIZE + 1); float lookY = random(height + cCELL_SIZE + 1); int brightness = int(random(25, 101)); e.setLookPoint(int(lookX / cCELL_SIZE) * cCELL_SIZE - int(adjustmentValueX), int(int(lookY) / cCELL_SIZE) * cCELL_SIZE - int(adjustmentValueY)); for (int v = 0; v < maxV; v++) { for (int h = 0; h < maxH; h++) { if (random(40) < 1.0) continue; e.setSize( int(cCELL_SIZE * ((random(cEYE_RATIO - 0.25, cEYE_RATIO + 0.09) + random(cEYE_RATIO - 0.25, cEYE_RATIO + 0.09)) / 2))); e.setPosition(int(0.0 - adjustmentValueX) + cCELL_SIZE * h + cCELL_SIZE / 2, int(0.0 - adjustmentValueY) + cCELL_SIZE * v + cCELL_SIZE / 2); hue = random(360); e.setEyeballColor(color(hue, 35, 100)); e.setIrisColor(color(int(hue + 180) % 360, 35, brightness)); e.setIrisRatio(random(0.4, 0.6)); e.draw(); } } }
Eye.pde
// Eye class Eye { int x; int y; int size; int lookX = 0; int lookY = 0; float lookAngle = 0.0; color eyeballColor = color(255); color irisColor = color(0); float irisRatio = 0.5; Eye(int tmpX, int tmpY, int tmpSize) { x = tmpX; y = tmpY; size = tmpSize; } void setPosition(int tmpX, int tmpY) { x = tmpX; y = tmpY; setLookPoint(lookX, lookY); } void setSize(int tmpSize) { size = tmpSize; } void setLookPoint(int tmpX, int tmpY) { lookX = tmpX; lookY = tmpY; lookAngle = atan2(tmpY - y, tmpX - x); } void setEyeballColor(color tmpColor) { eyeballColor = tmpColor; } void setIrisColor(color tmpColor) { irisColor = tmpColor; } void setIrisRatio(float tmpRatio) { irisRatio = tmpRatio; } void draw() { pushMatrix(); translate(x, y); noStroke(); fill(eyeballColor); ellipse(0, 0, size, size); rotate(lookAngle); fill(irisColor); ellipse(size / 2 - size * irisRatio / 2, 0, size * irisRatio, size * irisRatio); popMatrix(); } }