見出し画像

Generative Art #128

Code

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

void draw() {
  background(#383E37);
  tile();
}

void tile() {
  int count = 10;
  float w = width/count;
  float noiseScale = 100;
  for (int j = 0; j < count; j++) {
    for (int i = 0; i < count; i++) {
      float angle = map(noise(i / noiseScale, j / noiseScale), 0, 1, 0, TAU);
      push();
      translate(i*w + w/2, j*w + w/2);
      rotate(angle);
      fill(getCol());
      square(0, 0, w * 0.85);
      form(w * 0.85);
      pop();
    }
  }
}

void form(float s) {
  float r = random(1);
  int c = 5;
  float w = s/c;
  float hs = s/2;
  fill(getCol());
  if (r > 4.0/5.0) {
    for (float j = -hs; j < hs; j+= w*2) {
      for (float i = -hs; i < hs; i+= w*2) {
        square(i + w/2, j + w/2, w);
      }
    }
    for (float j = w-hs; j < hs; j+= w*2) {
      for (float i = w-hs; i < hs; i+= w*2) {
        square(i + w/2, j + w/2, s/5);
      }
    }
  } else if (r > 3.0/5.0) {
    for (float j = -hs; j < hs; j+= w*2) {
      for (float i = -hs; i < hs; i+= w*2) {
        square(i + w/2, j + w/2, w);
      }
    }
  } else if (r > 2.0/5.0) {
    beginShape();
    vertex(-hs, hs);
    for (float x = -hs; x <= hs + 1; x ++) {
      vertex(x, map(noise(x/70, r * 10), 0, 1, -hs, hs));
    }
    vertex(hs, hs);
    endShape();
  } else if (r > 1.0/5.0) {
    for (float ss = s; ss > 0; ss -= w) {
      fill(getCol());
      square(0, 0, ss);
    }
  } else {
    circle(0, 0, s * 0.8);
  }
}

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

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

int[] colors = {#ed1c24, #fdfffc, #235789, #f1d302, #020100};
int getCol() {
  return colors[(int)random(colors.length)];
}

愉快にタイリングして角度にパーリンノイズを適用。

Happy coding!!

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