見出し画像

Generative Art #195

画像1

画像2

画像3

画像4

Code

void setup() {
 size(800, 800);
 pixelDensity(2);
 noLoop();
}

void draw() {
 background(getCol());
 for (int i=0; i<10; i++) {
   color col = getCol();
   stroke(col);
   fill(col);
   rectRec(50, 50, width-100);
 }
}

void rectRec(float x, float y, float s) {
 int c = int(random(2, 4));
 float ss = s/c;
 for (int i=0; i<c; i++) {
   for (int j=0; j<c; j++) {
     if (random(1) < 0.5 && ss > 100) {
       rectRec(x+i*ss, y+j*ss, ss);
     } else {
       if(random(1) < 0.5){
       form(x+i*ss+ss/2, y+j*ss+ss/2, ss);
       }
     }
   }
 }
}

void form(float x, float y, float s) {
 float hs = s/2;
 push();
 translate(x, y);
 rotate(int(random(2))*HALF_PI);
 beginShape();
 vertex(-hs, 0);
 bezierVertex(-hs/2, 0, 0, -hs/2, 0, -hs);
 vertex(hs, -hs);
 vertex(hs, 0);
 bezierVertex(hs/2, 0, 0, hs/2, 0, hs);
 vertex(-hs, hs);
 endShape(CLOSE);
 pop();
}

void mousePressed() {
 redraw();
}

void keyPressed() {
 if (key == 's')saveFrame("####.png");
}

int[] colors = {#d00000, #ffba08, #3f88c5, #032b43, #136f63};
int getCol() {
 return colors[(int)random(colors.length)];
}

再帰的に分割した四角形の中に↓こんな形を配置しました。

画像5

それをいくつも重ねてどう面白い形を作れるかの実験。

Happy coding!

応援してくださる方!いつでもサポート受け付けてます!