見出し画像

Generative Art #105

Code

ArrayList<PVector> position = new ArrayList<PVector>();
int[] colors = {#880D1E, #DD2D4A, #F26A8D, #F49CBB, #CBEEF3, #FFF703};
int drawMode = 1;

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

void draw() {
  background(255);
  if (drawMode == 2)background(0);
  tile();
  node();
}

void tile() {
  int c = 10;
  float w = width/c;
  strokeWeight(1);

  for (int j = 0; j < c; j++) {
    for (int i = 0; i < c; i++) {
      myRect(i*w, j*w, w, w);
    }
  }
  for (int j = 0; j < c+1; j++) {
    for (int i = 0; i < c+1; i++) {
      if (random(1) < 0.2) {
        myCircle(i*w, j*w, w*(int)random(1, 3));
        position.add(new PVector(i*w, j*w));
      }
    }
  }
}

void myRect(float x, float y, float w, float h) {
  int c = int(w * 150);
  pushMatrix();
  translate(x+w/2, y+w/2);
  rotate(HALF_PI * (int)random(4));
  stroke(getCol(), random(20, 100));
  for (int i = 0; i < c; i ++) {
    float wr = random(random(w));
    float rh = random(h);
    point(-w/2+wr, -h/2+rh);
  }
  popMatrix();
}

void myCircle(float x, float y, float s) {
  float r = s*0.5;
  int c = int(s * 80);
  stroke(getCol(), random(20, 100));
  for (int i = 0; i < c; i++) {
    float angle = random(TAU);
    float radius = 1-random(random(random(1)));
    point(x+cos(angle)*r*radius, y+sin(angle)*r*radius);
  }
}

void node() {
  for (PVector p : position) {
    for (PVector other : position) {
      float d = dist(other.x, other.y, p.x, p.y);
      if (p != other) {
        if (d < 180) {
          stroke(0, random(50, 100));
          if (drawMode == 2)stroke(255, random(50, 100));
          line(other.x, other.y, p.x, p.y);
        }
      }
    }
  }
}

int getCol() {
  return colors[(int)random(colors.length)];
}

void mousePressed() {
  redraw();
  position.clear();
}

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

点の数を数えてみたら

約15万個ッ!重いッ!

後から粒子加工もいいけど、Processingで表現するのもおもしろい。

Happy coding!

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