見出し画像

Generative Art #116

Code

Circle[] c = new Circle[550];

void setup() {
  size(840, 840);
  pixelDensity(2);
  rectMode(CENTER);
  background(getCol());
  for (int i = 0; i < c.length; i ++) {
    c[i] = new Circle();
  }
}

void draw() {
  for (int i = 0; i < c.length; i ++) {
    c[i].run();
  }
}

int[] colors = {#E122F0, #F1C6F5, #F1F543, #FA9C38, #FA3838};
int getCol() {
  return colors[(int)random(colors.length)];
}

void mousePressed() {
  background(getCol());
  for (int i = 0; i < c.length; i ++) {
    c[i] = new Circle();
  }
}

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

//-----------------------------------------------------------------

class Circle {
  PVector pos;
  float d;
  float angle;
  color c, c1, c2;
  Circle() {
    pos = new PVector(random(width), random(height));
    d = 100;
    c1 = color(getCol());
    c2 = color(getCol());
  }

  void run() {
    show();
    move();
  }

  void show() {
    noStroke();
    c = lerpColor(c1, c2, map(d, 100, 0, 1, 0)); 
    fill(c);

    circle(pos.x, pos.y, d);
    //square(pos.x, pos.y, d);
    //pushMatrix();
    //translate(pos.x, pos.y);
    //rotate(angle);
    //square(0, 0, d);
    //popMatrix();
  }

  void move() {
    if (d > 0) {
      d -= 1;
      angle += PI/90;
    }
  }
}

ボロノイ図のことは詳しくわからないが、多分このアプローチでもボロノイだと思う。

確かドロネー図が点を三角形で結んで、その垂直二等分線がボロノイ図みたいなことだったよね。

自然界の数学みたいな構造は美しい。蜂の巣とかもこの構造だよね。

気が向いたらボロノイを勉強しよう。

Happy coding!


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