見出し画像

Generative Art #141

Code

int count = 4;

void setup() {
 size(840, 840);
 pixelDensity(2);
 noLoop();
 rectMode(CENTER);
}

void draw() {
 background(#ffffff);
 squareRec(width/2, height/2, width, count);
}

void squareRec(float x, float y, float s, int n) {
 stroke(50);
 strokeWeight(0.5);
 fill(getCol());
 square(x, y, s);

 n--;
 if (n >= 0) {
   float b = 0.2;
   float hs = s/2;
   float angle = random(0.1, 0.9) * HALF_PI;
   float ss = hs/(sin(angle) + cos(angle));
   
   push();
   translate(x - hs/2, y - hs/2);
   if (random(1) > b) {
     squareRec(0, 0, hs, n);
   } else {
     rotate(angle);
     squareRec(0, 0, ss, n);
   }
   pop();
   
   angle = random(0.1, 0.9) * HALF_PI;
   ss = hs/(sin(angle) + cos(angle));
   push();
   translate(x - hs/2, y + hs/2);
   if (random(1) > b) {
     squareRec(0, 0, hs, n);
   } else {
     rotate(angle);
     squareRec(0, 0, ss, n);
   }
   pop();
   
   angle = random(0.1, 0.9) * HALF_PI;
   ss = hs/(sin(angle) + cos(angle));
   push();
   translate(x + hs/2, y - hs/2);
   if (random(1) > b) {
     squareRec(0, 0, hs, n);
   } else {
     rotate(angle);
     squareRec(0, 0, ss, n);
   }
   pop();
   
   angle = random(0.1, 0.9) * HALF_PI;
   ss = hs/(sin(angle) + cos(angle));
   push();
   translate(x + hs/2, y + hs/2);
   if (random(1) > b) {
     squareRec(0, 0, hs, n);
   } else {
     rotate(angle);
     squareRec(0, 0, ss, n);
   }
   pop();
 }
}

void mousePressed() {
 redraw();
}

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

int[] colors = {#011627 ,#ff3366 ,#2ec4b6 ,#f6f7f8 ,#20a4f3};
//int[] colors = {#114b5f ,#456990 ,#e4fde1 ,#f45b69 ,#6b2737};
int getCol() {
 return colors[(int)random(colors.length)];
}

画像加工あり。

僕がよく使ってる正方形のフラクタルに角度を追加。
最近作った角度をから正方形の辺の長さをものとの組み合わせ。

別のタイミングで作ったモノが組み合わさる、イマジネーションからイマジネージョンが生まれる、これは大きい視点でみたらイマジネーションのフラクタルだ!

Happy coding!

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