見出し画像

Generative Art #166

Code

int actRandomSeed = (int)random(10000);
float t = 0;
float st = 0;

void setup() {
 size(900, 900, OPENGL);
 pixelDensity(2);
 rectMode(CENTER);
}

void draw() {
 randomSeed(actRandomSeed);
 background(255);
 
 push();
 translate(width/2, (height/2) - 100, -200);
 rotateX(radians(40));
 rotateZ(t);
 translate(-width/2, -height/2);
 tileRec(0, 0, width, width);
 pop();

 t += 0.002;
 st += 2;

 //saveFrame("output/####.png");
}

void tileRec(float x_, float y_, float w_, float h_) {
 int tileCount = (int)random(2, 4);
 float w = w_/tileCount;

 for (float x = x_; x < x_ + w_ -1; x += w) {
   for (float y = y_; y < y_ + h_ - 1; y += w) {
     float ww = constrain(st, 0, w*0.8);
     if (random(1) < 0.4 && w > 50) {
       tileRec(x, y, w, w);
     } else {
       noFill();
       stroke(0);
       square(x+w/2, y+w/2, w);
       push();
       translate(x+w/2, y+w/2);
       noStroke();
       fill(getCol());
       if (random(1) < 0.333) {
         myBox(ww);
       } else if (random(1) < 0.666) {
         square(0, 0, ww);
       } else {
         sphere(ww/2);
       }
       pop();
     }
   }
 }
}

void myBox(float s) {
 float hs = s/2;
 fill(getCol());
 for (int i=0; i<4; i++) {
   rotateZ(HALF_PI);
   beginShape();
   fill(getCol());
   vertex(-hs, -hs, -hs);
   vertex(-hs, -hs, hs);
   vertex(-hs, hs, hs);
   vertex(-hs, hs, -hs);
   endShape();
 }
 beginShape();
 fill(getCol());
 vertex(-hs, -hs, hs);
 vertex(hs, -hs, hs);
 vertex(hs, hs, hs);
 vertex(-hs, hs, hs);
 endShape();

 beginShape();
 fill(getCol());
 vertex(-hs, -hs, -hs);
 vertex(hs, -hs, -hs);
 vertex(hs, hs, -hs);
 vertex(-hs, hs, -hs);
 endShape();
}

void mousePressed() {
 actRandomSeed = (int)random(4649);
 st = 0;
}

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

int[] colors = {#50514f, #f2553a, #ffd530, #2fa4d6, #23c6ab};
int getCol() {
 return colors[(int)random(colors.length)];
}

久しぶりの動画作品。

正方形を再帰的に分割した中に球、立法、正方形をランダムに配置。

Happy coding!

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