見出し画像

Generative art #107

Code

float noiseStep = 0.03;

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

void draw() {
  background(250);
  divideRect(0, 0, width, height, 13);

  for (int y = 0; y < height; y ++) {
    for (int x = 0; x < width; x ++) {
      stroke(map(noise(x * noiseStep, y * noiseStep), 0, 1, 0, 255), 50);
      point(x, y);
    }
  }
}

void divideRect(float x, float y, float w, float h, int n) { 
  noStroke();
  fill(getCol());
  if (n == 0)rect(x, y, w, h);

  n--;

  if (n>=0) {
    if (w>=h) {
      float randomW = random(w*0.1, w*0.9);
      divideRect(x, y, randomW, h, n);
      divideRect(x+randomW, y, w-randomW, h, n);
    }

    if (w<h) {
      float randomH = random(h*0.1, h*0.9);
      divideRect(x, y, w, randomH, n);
      divideRect(x, y+randomH, w, h-randomH, n);
    }
  }
}

int[] colors = {#292F36, #4ECDC4, #F7FFF7, #FF6B6B, #FFE66D, #1470DE, #FA4444};
int getCol() {
  return colors[(int)random(colors.length)];
}

void mousePressed() {
  redraw();
  noiseSeed((int)random(1000));
}

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

構造はこれと一緒です。

これに質感を与えるためにpoint()並べてパーリンノイズを付けた。

この形ってモザイクアートみたいなのもできそうなんだよね。

もう少し研究できそう。

Happy coding!


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