見出し画像

Generative Art #162

Code

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

void draw() {
 background(getCol());
 noStroke();
 for (int i=0; i<1000; i++) {
   fill(getCol());
   noiseCircle(random(width), random(height), random(10, 100));
   noiseSeed(int(random(10000)));
 }

 tileRec(0, 0, width, height);

 noiseFilter();
}

void tileRec(float x_, float y_, float w_, float h_) {
 int tileCountW = (int)random(2, 6);
 int tileCountH = (int)random(2, 6);
 float tileW = w_/tileCountW;
 float tileH = h_/tileCountH;

 for (float x = x_; x < x_ + w_ -1; x += tileW) {
   for (float y = y_; y < y_ + h_ - 1; y += tileH) {
     if (random(1) < 0.3 && tileW > 100) {
       tileRec(x, y, tileW, tileH);
     } else {
       noFill();
       strokeWeight(0.7);
       stroke(255);
       rect(x, y, tileW, tileH);

       if (random(1) < 0.7) {
         fill(getCol(), 200);
         rect(x+tileW*0.05, y+tileH*0.05, tileW*0.9, tileH*0.9);
       }

       if (random(1) < 0.3) {
         fill(getCol(), 200);
         circle(x+tileW*0.5, y+tileH*0.5, (tileW+tileH) * 0.1);
       }
     }
   }
 }
}

void noiseCircle(float x, float y, float d) {
 float noiseMax = 0.5;

 push();
 translate(x, y);
 beginShape();
 for (float a=0; a<TAU; a+=TAU/180) {
   float xoff = map(cos(a), -1, 1, 0, noiseMax);
   float yoff = map(sin(a), -1, 1, 0, noiseMax);
   float r = map(noise(xoff, yoff), 0, 1, 0, d);
   float posx = r * cos(a);
   float posy = r * sin(a);

   vertex(posx, posy);
 }
 endShape(CLOSE);
 pop();
}

void noiseFilter() {
 for (int i=0; i<300000; i++) {
   fill(255, 50);
   noStroke();
   circle(random(width), random(height), random(1));
 }
}

void mousePressed() {
 redraw();
}

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

//int[] colors = {#820933, #d84797, #d2fdff, #3abeff, #26ffe6};
int[] colors = {#ffc421, #ff2173, #f86624, #ea3546, #662e9b};

int getCol() {
 return colors[(int)random(colors.length)];
}

Happy coding!!

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