Generative Art #178
Code
void setup() {
size(900, 900);
pixelDensity(2);
noLoop();
rectMode(CENTER);
}
void draw() {
background(getCol());
push();
translate(width/2, height/2);
rotate(int(random(2))*QUARTER_PI);
translate(-width, -height);
rectRec(0, 0, width*2, height*2);
pop();
//saveFrame("output/####.png");
//if (frameCount > 100)exit();
}
void rectRec(float x_, float y_, float w_, float h_) {
int tileCountW = (int)random(2, 6);
int tileCountH = (int)random(2, 6);
float w = w_/tileCountW;
float h = h_/tileCountH;
float dec = 5;
for (float x = x_; x < x_ + w_ -1; x += w) {
for (float y = y_; y < y_ + h_ - 1; y += h) {
if (random(1) < 0.8 && w+h > 300) {
rectRec(x, y, w, h);
} else {
push();
translate(x+w/2, y+h/2);
rotate(random(-1, 1)*radians(1));
fill(getCol(), 240);
stroke(175, 50);
strokeWeight(1);
rect(0, 0, w-dec, h-dec, w*0.01);
fill(getCol());
form(0, 0, w-dec, h-dec);
pop();
}
}
}
}
void form(float x, float y, float w, float h) {
int p = int(random(5));
int wc = int(random(1, 10));
int hc = int(random(1, 10));
float ws = w/wc, hs = h/hc;
float dec = random(0.5, 1);
push();
translate(x-w/2, y-h/2);
for (int i=0; i<wc; i++) {
for (int j=0; j<hc; j++) {
if (p == 0) {
if (ws > hs) {
ellipse(i*ws+ws/2, j*hs+hs/2, hs*dec, hs*dec);
} else {
ellipse(i*ws+ws/2, j*hs+hs/2, ws*dec, ws*dec);
}
}
if (p == 1) {
if (ws > hs) {
rect(i*ws+ws/2, j*hs+hs/2, hs*dec, hs*dec);
} else {
rect(i*ws+ws/2, j*hs+hs/2, ws*dec, ws*dec);
}
}
if (p == 2) {
if (ws > hs) {
rect(i*ws+ws/2, j*hs+hs/2, hs*dec, hs*dec, hs*0.2);
} else {
rect(i*ws+ws/2, j*hs+hs/2, ws*dec, ws*dec, ws*0.2);
}
}
if (p == 3) {
rect(i*ws+ws/2, j*hs+hs/2, ws*dec, hs*dec);
}
if (p == 4) {
rect(i*ws+ws/2, j*hs+hs/2, ws*dec, hs*dec, ws*0.2);
}
}
}
pop();
}
void mousePressed() {
redraw();
}
void keyPressed() {
if (key == 's')saveFrame("####.png");
}
int[] colors = {#479de8, #ef476f, #ffd166, #06d6a0, #fffcf9, #000000};
int getCol() {
return colors[(int)random(colors.length)];
}
再帰的に四角形を分割しています。縦と横で分割する数を変えることで大きな正方形から矩形が生まれます。
その正方形や矩形のたちの中に四角形や円形をグリッド上に配置しています。
配置された図形の大きさや配置される数をランダムにしたり角度を少しだけずらしてカオス感を出しました。
全体を回転させる角度を0度か45度の2択にして構造が変わったような表現を作りました。
Happy coding!
応援してくださる方!いつでもサポート受け付けてます!