つよくなりたいなあ

地に足をつけず世界を生きぬくブログです

ひっくり返るドット

/*
 * 2018/06/07
 * flip dots
 */


int X_NUM = 10;
int Y_NUM = 10;

void setup() {
  size(640, 640);
  ellipseMode(CENTER);
  colorMode(HSB, 360, 100, 100);
  noStroke();
  fill(100);


}

void draw() {
  background(350);

  translate(width/2, height/2);
  for (int y = 0; y < Y_NUM; y++) {
    for (int x = 0; x < X_NUM; x++) {
      float angle = PI * float (x + y * X_NUM)/(2 * Y_NUM);
      float v = pow(abs(sin(angle - frameCount * 0.03)), 12);
      pushMatrix();
      translate((x-(X_NUM - 1)/2.0)*100, (y - (Y_NUM - 1)/2.0)*100);

      drawRect(v);
      popMatrix();
    }
  }

}

void drawRect(float v) {
  float posY = map(v, 0, 1, 0, 1);
  float sizeX = map(sin(v * PI), 0, 1, 40, 0);
  fill(lerpColor(color(320, 240, 100), color(80, 64, 150), v));
  ellipse(0, posY, sizeX, 40);
}