見出し画像

ProcessingでGenerative art #100

Code

int actRandomSeed = (int)random(10000);
int count = 6;

void setup() {
  size(840, 840);
  pixelDensity(2);
  noLoop();
  strokeCap(SQUARE);
}

void draw() {
  randomSeed(actRandomSeed);
  background(#F0F0F0);
  squareRecursion(0, 0, width, count);
}

void squareRecursion(float x, float y, float s, int n) {
  noFill();
  strokeWeight(1);
  stroke(getCol());
  square(x, y, s);
  form(x, y, s);

  n--;
  if (n >= 0) {
    float probability = map(n, 0, count-1, 0.8, 0);
    float hs = s/2;
    if (random(1) > probability) {
      squareRecursion(x, y, hs, n);
    }
    if (random(1) > probability) {
      squareRecursion(x+hs, y, hs, n);
    }
    if (random(1) > probability) {
      squareRecursion(x+hs, y+hs, hs, n);
    }
    if (random(1) > probability) {
      squareRecursion(x, y+hs, hs, n);
    }
  }
}

void form(float x, float y, float s) {
  int count = (int)random(4, 8);
  float w = s/count;
  float rw = random(s/count);
  strokeWeight(rw);
  fill(getCol());

  if (random(1) > 2.0/3.0) {
    for (float i = x+w; i < x+s; i += w) {
      line(i, y, i, y+s);
    }
  } else if (random(1) > 1.0/3.0) {
    for (float i = y+w; i < y+s; i += w) {
      line(x, i, x+s, i);
    }
  } else if (random(1) > 0.0/3.0) {
      noStroke();
      circle(x + s/2, y + s/2, s);
  }
}

int[] colors = {#FF0004, #FF00C4, #00FFDF, #FF5500, #001BFF, #FEFF00,#272727, #F0F0F0};
//int[] colors = {#272727, #F0F0F0};
int getCol() {
  return colors[(int)random(colors.length)];
}

void mousePressed() {
  redraw();
  actRandomSeed = (int)random(1000000);
}

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

パンパカパァーン!

別記事に100個終わった感想とか、その他もろもろ書きます。

本当にありがとうございました!

Happy coding!

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