Daily Creative Coding

元「30 min. Processing」。毎日、Creative Codingします。

マウスを避けるドット

/**
* Untouchable Dots
*
* @author aa_debdeb
* @date 2015/11/12
*/ 


void setup(){
  size(500, 500);
  smooth();
  frameRate(30);
}

void draw(){
  background(255);
  noStroke();
  fill(0);
  for(int x = 0; x < 50; x++){
    for(int y = 0; y < 50; y++){
      PVector pos = new PVector(x * 10 + 5, y * 10 + 5);
      PVector mouse = new PVector(mouseX, mouseY);
      float distance = pos.dist(mouse);
      PVector variant = PVector.sub(mouse, pos);
      variant.normalize();
      variant.mult(20.0 / pow(distance, 1.0 / 10.0));
      PVector newPos = PVector.sub(pos, variant);
      ellipse(newPos.x, newPos.y, 4, 4);
    }
  }
}