{"size": 1101, "ext": "js", "max_stars_repo_path": "diffusion-limited-aggregation/particle.js", "max_stars_repo_name": "PremjitAdhikary/Mesmerize", "max_stars_repo_stars_event_min_datetime": "2020-11-20T16:12:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-26T15:03:45.000Z", "max_issues_repo_path": "diffusion-limited-aggregation/particle.js", "max_issues_repo_name": "PremjitAdhikary/Mesmerize", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffusion-limited-aggregation/particle.js", "max_forks_repo_name": "PremjitAdhikary/Mesmerize", "max_forks_repo_forks_event_min_datetime": "2020-02-19T10:38:02.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-19T10:38:02.000Z"}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 23.4255319149, "max_line_length": 89, "alphanum_fraction": 0.6067211626}
class Particle {

  constructor(start, endReached, velocityFunc, size, color, 
    onStuckFunc = () => {}, loops = 50) {
    this._current = start.copy();
    this.endReached = endReached;
    this.velocityFunc = velocityFunc;
    this._size = size;
    this._color = color;
    this.onStuckFunc = onStuckFunc;
    this._loops = loops;

    this._stuck = false;
    this._touchDist = (size * size * 1.1);
  }

  show() {
    noStroke();
    fill(this._color);
    circle(this._current.x, this._current.y, this._size);
  }

  touches(anotherParticle) {
    let distSq = this.squareDist(anotherParticle._current.x, anotherParticle._current.y);
    return distSq < this._touchDist;
  }

  walk() {
    if (this._stuck) return;
    let currLoop = 0;
    while(!this._stuck && currLoop < this._loops) {
      this.velocityFunc(this._current, this._size);
      if (this.endReached(this)) {
        this._stuck = true;
        this.onStuckFunc(this);
      }
      currLoop++;
    }
  }

  squareDist(x, y) {
    let X = (this._current.x - x);
    let Y = (this._current.y - y);
    return X*X + Y*Y;
  }

}