見出し画像

ProcessingでGenerative art #45

Code

void setup() {
  size(1000, 700);
  pixelDensity(2);
  colorMode(HSB, 360, 100, 100, 100);
  noLoop();
}

void draw() {
  drawRect(0, 0, width, height);
  drawSquare(width/2, height/2, 200, 5);
}

void drawSquare(float x, float y, float s, int n) {
  pushMatrix();
  translate(x, y);
  drawRect(- s/2, - s/2, s, s);
  n--;
  if (n > 0) {
    for (float angle = 0; angle < TWO_PI; angle += TWO_PI /4 ) {
      pushMatrix();
      rotate(PI/4);
      rotate(angle);
      float len = s*random(1, 2.5);
      stroke(360);
      strokeWeight(0.5);
      line((s/2) * sqrt(2), 0, len, 0);
      drawSquare(len, 0, s * 0.6, n);
      popMatrix();
    }
  }
  popMatrix();
}

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 = 15;
  }
  color c1 = color(h, 10, 90, alph);
  color c2 = color(h, 70, 80, alph);
  noStroke();
  if (random(1) > 0.5) {
    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 mousePressed() {
  redraw();
}

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

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