見出し画像

Generative Art #164

Code

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

void draw() {
 background(getCol());

 for (int i=0; i<2; i++) {
   fill(0, 26);
   noStroke();
   rect(width/2, height/2, width, height);
   tile(0, 0, width-1);
 }

 saveFrame("output/####.png");
 if (frameCount == 100)exit();
}

void tile(float x_, float y_, float w_) {
 int count = (int)random(2, 4);
 float w = w_/count;

 for (float x=x_; x<x_+w_-1; x+=w) {
   for (float y=y_; y<y_+w_-1; y+=w) {
     float cx = x+w/2;
     float cy = y+w/2;
     int p = (int)random(5);
     float r1 = random(w/2), r2 = random(w/2), r3 = random(w/2), r4 = random(w/2);
     color col = getCol();
     
     if (random(1) < 0.6 && w > 50) {
       tile(x, y, w);
     } else {
       noFill();
       stroke(0);
       strokeWeight(0.5);
       square(cx, cy, w);

       noStroke();
       if (p == 1) {
         circleShadow(cx, cy, w-1);
         fill(col);
         circle(cx, cy, w-1);
       }
       if (p == 2) {
         circleShadow(cx, cy, w-1);
         fill(col);
         myCircle(cx, cy, w-1);
       } 
       if (p == 3) {
         rectShadow(cx, cy, w-1, r1, r2, r3, r4);
         fill(col);
         rect(cx, cy, w-1, w-1, r1, r2, r3, r4);
       } 
       if (p == 4) {
         rectShadow(cx, cy, w-1, r1, r2, r3, r4);
         fill(col);
         myRect(cx, cy, w-1, r1, r2, r3, r4);
       }
     }
   }
 }
}

void myRect(float x, float y, float s, float tl, float tr, float bl, float br) {
 for (float i=s; i>0; i-=20) {
   fill(getCol());
   rect(x, y, i, i, tl, tr, bl, br);
 }
 noiseSeed(int(random(1000)));
}

void myCircle(float x, float y, float d) {
 for (float i=d; i>0; i-=20) {
   fill(getCol());
   circle(x, y, i);
 }
 noiseSeed(int(random(1000)));
}

float maxShift = 40;
int c = 100;
void rectShadow(float x, float y, float s, float tl, float tr, float bl, float br) {
 noStroke();
 for (int i=0; i<c; i++) {
   float alph = map(i, 0, c-1, 10, 0);
   float shift = map(i, 0, c-1, 0, maxShift);
   fill(0, alph);
   rect(x+shift, y+shift, s, s, tl, tr, bl, br);
 }
}

void circleShadow(float x, float y, float d) {
 noStroke();
 for (int i=0; i<c; i++) {
   float alph = map(i, 0, c-1, 10, 0);
   float shift = map(i, 0, c-1, 0, maxShift);
   fill(0, alph);
   circle(x+shift, y+shift, d);
 }
}

void mousePressed() {
 redraw();
}

int[] colors = {#a20021, #f4385e, #f79d5c, #f3752b, #9f9ff4};
//int[] colors = {#eac435, #345995, #03cea4, #fb4d3d, #ca1551};
int getCol() {
 return colors[(int)random(colors.length)];
}

再帰的に作ったタイルを重ねました。

今回のテーマは陰影です。

for (int i=0; i<2; i++) {
   fill(0, 26);
   noStroke();
   rect(width/2, height/2, width, height);

   tile(0, 0, width-1);
 }

こんな感じで先に描画されたものを少し暗くして奥行き感を表現しました。

影は少し工夫してズズズっと伸びるような雰囲気にしてみました。

粒子加工ありです。

Happy coding!!

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