見出し画像

ProcessingでGenerative art #93

この円を並べる構造が死ぬほど好き。

集合体の気持ち悪さと紙一重の美しさ。

Code

int actRandomSeed = 0;

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

void draw() {
  randomSeed(actRandomSeed);
  background(getCol());
  circles();
}

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

  ArrayList<PVector> points = new ArrayList<PVector>();
  int cc = int(random(100000*random(1)));
  for (int i = 0; i < cc; 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);
    circle(p.x, p.y, p.z*0.9);
  }
} 

void circle(float posX, float posY, float diameter) {
  float radius = diameter/2;
  color col1 = getCol();
  pushMatrix();
  translate(posX, posY);
  rotate(random(PI));
  beginShape();
  noStroke();
  fill(getCol());
  for (float theta = 0; theta <= TWO_PI; theta += radians(1)) {
    float x = radius * cos(theta);
    float y = radius * sin(theta);
    if (theta > TWO_PI/2) {
      fill(col1);
    } 
    vertex(x, y);
  }
  endShape();
  popMatrix();
}

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

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

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

Happy coding!!

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