見出し画像

ProcessingでGenerative art#31

Code

int num = 6;
float rad;

void setup() {
  size(700, 600);
  noFill();
  noLoop();
  colorMode(HSB, 360, 100, 100, 100);
}

void draw() {
  background(0);
  divideRect(0, 0, width, height, num);
  drawCircle(width/2, height/2, height);
  for (int i=0; i<20; i++) {
    if (i>=15) {
      rad = random(150, 200);
    } else {
      rad = random(20);
    }
    float x = map(randomGaussian(), -4, 4, 0, width); 
    float y = map(randomGaussian(), -4, 4, 0, height); 
    drawCircle(x, y, rad);
  }
  for (int i=0; i<15; i++) {
    float rad = random(20); 
    float x = map(randomGaussian(), -4, 4, 0, width); 
    float y = map(randomGaussian(), -4, 4, 0, height); 
    drawCircle(x, y, rad);
  }
}

void mousePressed() {
  redraw();
}

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

void divideRect(float x, float y, float w, float h, int n) {
  float randw = random(w); 
  float randh = random(h);
  if (n>0) {
    n--;
    if (w>h) {
      divideRect(x, y, randw, h, n);
      divideRect(x+randw, y, w-randw, h, n);
      if (n==0) {
        drawRect(x, y, randw, h);
        drawRect(x+randw, y, w-randw, h);
      }
    } else {
      divideRect(x, y, w, randh, n);
      divideRect(x, y+randh, w, h-randh, n);
      if (n==0) {
        drawRect(x, y, w, randh);
        drawRect(x, y+randh, w, h-randh);
      }
    }
  }
}

void drawRect(float _x, float _y, float _w, float _h) {
  float hran = random(1);
  float h = 200;
  float alph = 100;
  if (hran > 0.75) {
    h = 298;
  } else if (hran > 0.5) {
    h = 340;
  } else if (hran > 0.25) {
    h = 113;
  }
  color c1 = color(h, 10, 90, alph);
  color c2 = color(h, 70, 80, alph);
  noStroke();
  if (_w>_h) {
    for (float s=_w; s>0; s-=1) {
      color c = lerpColor(c1, c2, s/_w);
      fill(c);
      rect(_x, _y, s, _h);
    }
  } else {
    for (float s=_h; s>0; s-=1) {
      color c = lerpColor(c1, c2, s/_h);
      fill(c);
      rect(_x, _y, _w, s);
    }
  }
}

void drawCircle(float _x, float _y, float _r) {
  noFill();
  float h = random(360);
  color c1 = color(h, 100, 50, 50);
  color c2 = color(h, 100, 100, 0);
  for (float rad = _r; rad < _r * 2; rad+=1) {
    color c = lerpColor(c1, c2, rad / (_r*2));
    stroke(c);
    ellipse(_x, _y, rad, rad);
  }
}

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