見出し画像

Generative Art #119

Code

ArrayList<Form>form;
int[] colors = new int [5];
int actRandomSeed = (int)random(10000);

void setup() {
  size(840, 840, P2D);
  pixelDensity(2);
  smooth(8);
  rectMode(CENTER);
  colorMode(HSB, 360, 100, 100, 100);
  background(0);
  newForm();
}

void draw() {
  for (Form f : form) {
    f.run();
  }
}

void tile() {
  int count = 16;
  float w = (width/count)-1;
  stroke(#ffffff);
  noFill();
  for (int j = 0; j < count; j++) {
    for (int i = 0; i < count; i++) {
      rect(count + i*w+w/2, count + j*w+w/2, w, w);
      if (random(1) > 0.7) {
        form.add(new Form(count + i*w+w/2, count + j*w+w/2, w));
      }
    }
  }
}

void newForm() {
  form = new ArrayList<Form>();
  for (int i = 0; i < colors.length; i ++) {
    colors[i] = color((int)random(360), 80, 80);
  }
  tile();
}
void mousePressed() {
  newForm();
}

void keyPressed() {
  if (key == 's')saveFrame("####.png");
  if (key == ' ') {
    background(0);
    newForm();
  }
}
int getCol() {
  return colors[int(random(colors.length))];
}

class Form {
  float x, y, s;
  float l;
  float maxL;
  float hs;
  float circleS;
  float angle;
  color c1, c2;
  Form(float x, float y, float s) {
    this.x = x;
    this.y = y;
    this.s = s;
    maxL = s * (int)random(5);
    l = 0;
    hs = s/2 - 5;
    circleS = s*0.15;
    angle = HALF_PI * (int)random(0, 4);
    c1 = getCol();
    c2 = getCol();
  }

  void show() {
    noStroke();
    stroke(0);
    pushMatrix();
    translate(x, y);
    rotate(angle);

    beginShape();
    fill(c1);
    vertex(-hs, -hs - l);
    vertex(hs, -hs - l);
    fill(c2);
    vertex(hs, hs);
    vertex(-hs, hs);
    endShape(CLOSE);
    fill(#ffffff, 50);
    circle(0, 0, circleS);
    circle(0, -l, circleS);
    popMatrix();
  }

  void move() {
    if (maxL > l) {
      l ++ ;
    }
  }

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

noteは10MBまでしか貼れないのでツイートしたのを貼る。

アニメーションさせるのって静止画よりも時間がかかるので避け気味だったのだけど作ってて楽しい。

グラデーションと重なりによって少し立体感が出るのが面白い。

ひとつひとつのバーは1~5マスの間で伸びる。

色は描画の度にランダムな5色が選ばれる様にしてみた。

Happy coding!

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