ProcessingでGenerative art #80
んっ!フラクタル!んっ!フラクタル!
Code
int count = 30;
float angle;
float colHue;
void setup() {
size(800, 800);
pixelDensity(2);
colorMode(HSB, 360, 100, 100, 100);
strokeWeight(1);
noLoop();
}
void draw() {
background(360, 5, 100);
for (int i = 0; i < 20; i ++) {
angle = radians(random(20, 120));
drawShape(random(width), random(height), random(100, 200), count);
}
}
void drawShape(float posX, float posY, float radius, int n) {
float ellipseSize = radius * 0.1;
float pX = 0, pY = 0;
pushMatrix();
translate(posX, posY);
rotate(angle);
for (float theta = 0; theta <= angle; theta += angle) {
float x = 0 + radius * cos(theta);
float y = 0 + radius * sin(theta);
for (int i = 0; i <= radius; i += 2) {
float shiftX = map(i, 0, radius, x, 0);
float shiftY = map(i, 0, radius, y, 0);
float shiftPX = map(i, 0, radius, pX, 0);
float shiftPY = map(i, 0, radius, pY, 0);
float colSaturation = map(i, 0, radius, 0, 100);
fill(colHue, colSaturation, 100);
triangle(0, 0, shiftX, shiftY, shiftPX, shiftPY);
noStroke();
}
randomHue();
fill(colHue, 100, 100);
stroke(0);
ellipse(x, y, ellipseSize, ellipseSize);
pX = x;
pY = y;
}
ellipse(0, 0, ellipseSize, ellipseSize);
n --;
if (n > 0) {
drawShape(pX, pY, radius* 0.9, n);
}
popMatrix();
}
void randomHue() {
if (random(1) > 0.75) colHue = 100;
else if (random(1) > 0.50) colHue = 314;
else if (random(1) > 0.25) colHue = 40;
else colHue = 180;
}
void mousePressed() {
redraw();
}
void keyPressed() {
if (key == 's')saveFrame("####.png");
if (keyCode == UP)count += 1;
if (keyCode == DOWN)count -= 1;
}
Happy Coding!!
応援してくださる方!いつでもサポート受け付けてます!