つよくなりたいなあ

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

マウスの位置でサイズがかわる円

f:id:heyassy:20180608224629j:plain

/*
 * 2018/06/08
 * shape
 */

float tileCount = 20;
color moduleColor = color(0);
int moduleAlpha = 180;
int actRandomSeed = 0;
int max_distance = 500;

void setup() {
  size(550, 550, P3D);
}

void draw() {
  background(255);
  smooth();
  noFill();

  randomSeed(actRandomSeed);
  stroke(moduleColor, moduleAlpha);
  strokeWeight(2);

  for (int gridY = 0; gridY < width; gridY += 20) {
    for (int gridX = 0; gridX < height; gridX += 20) {

      float diameter = dist(mouseX, mouseY, gridX, gridY);
      diameter = diameter/max_distance * 20;
      pushMatrix();
      translate(gridX, gridY, diameter * 1);
      ellipse(0, 0, diameter, diameter);
      popMatrix();

      if (mousePressed) {
        fill(100, 0, 220);
        noStroke();
      }
    }
  }
}

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