見出し画像

Generative Art #118

Code

int actRandomSeed = (int)random(1000000);

void setup() {
  size(800, 800);
  pixelDensity(2);
  colorMode(HSB, 360, 100, 100, 100);
  noStroke();
}

void draw() {
  randomSeed(actRandomSeed);
  background(#142127);
  circles();
}

void circles() {
  int cx = width/2; 
  int cy = height/2;

  ArrayList<PVector> points = new ArrayList<PVector>();
  int count = int(random(1000000));
  for (int i = 0; i < count; i++) {
    float s = random(10, 320);
    float d = random(cx*1.5-s);
    float a = random(TWO_PI);
    float x = cx + cos(a) * d;
    float y = cy + sin(a) * d;

    boolean add = true;
    for (int j = 0; j < points.size(); j++) {
      PVector p = points.get(j); 
      if (dist(x, y, p.x, p.y) < (s+p.z)*0.5) {
        add = false; 
        break;
      }
    }
    if (add) points.add(new PVector(x, y, s));
  }
  for (int i = 0; i < points.size(); i++) {
    PVector p = points.get(i);
    form(p.x, p.y, p.z);
  }
} 

void form(float x, float y, float d) {
  ArrayList<PVector> pos = new ArrayList<PVector>();
  float r = d/2;
  float update = TAU/int(random(3, 7));
  curveTightness(random(0, 6));
  pushMatrix();
  translate(x, y);
  rotate(random(TAU));
  noStroke();
  fill(getCol());

  for (float a = 0; a <= TWO_PI; a += update) {
    float x_ = r * cos(a);
    float y_ = r * sin(a);
    pos.add(new PVector(x_, y_));
  }

  beginShape();
  PVector start = pos.get(pos.size()-2);
  PVector end = pos.get(1);
  curveVertex(start.x, start.y);
  for (int i = 0; i < pos.size(); i++) {
    PVector p = pos.get(i);
    curveVertex(p.x, p.y);
  }
  curveVertex(end.x, end.y);
  endShape();
  popMatrix();
}

int[] colors = {#FF002F, #0F3EF2, #F705F4, #FFBC00, #00F9FF};
int getCol() {
  return colors[(int)random(colors.length)];
}

void mousePressed() {
  actRandomSeed = (int)random(100000);
}

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

これは完全にかわいい。

Circle packingの構造でcurveTightness()を活用。

map(mouseX,0, width, -5, 5);

こんな風にマッピングしていい感じのランダムな範囲を調べた。
値によって隣接する円にかぶってしまう。

circle packingの気持ち良さも出てんじゃないすか。

Happy coding!!!!

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