{"size": 958, "ext": "js", "max_stars_repo_path": "IntelligenceAndLearning/session4-neural-network/neural_network_animation/connection.js", "max_stars_repo_name": "frag997/p5-plus-plus", "max_stars_repo_stars_event_min_datetime": "2019-08-29T19:49:18.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-19T20:19:01.000Z", "max_issues_repo_path": "IntelligenceAndLearning/session4-neural-network/neural_network_animation/connection.js", "max_issues_repo_name": "fragreat/p5-plus-plus", "max_issues_repo_issues_event_min_datetime": "2018-03-15T14:11:15.000Z", "max_issues_repo_issues_event_max_datetime": "2018-07-18T08:37:45.000Z", "max_forks_repo_path": "IntelligenceAndLearning/session4-neural-network/neural_network_animation/connection.js", "max_forks_repo_name": "fernand0aguilar/p5-projects", "max_forks_repo_forks_event_min_datetime": "2021-03-16T14:18:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-16T14:18:03.000Z"}
{"max_stars_count": 3, "max_issues_count": 4, "max_forks_count": 1, "avg_line_length": 20.3829787234, "max_line_length": 66, "alphanum_fraction": 0.5762004175}
class Connection {
  constructor(from, to, weight){
    this.weight = weight;
    this.a = from;
    this.b = to;

    this.sending = false;
    this.sender = createVector();

    this.output = 0;
  }

  show(){
    stroke(0);
    strokeWeight(this.weight * 4);
    line(this.a.position.x, this.a.position.y,
      this.b.position.x, this.b.position.y);

    if(this.sending){
      fill(255, 0, 255);
      strokeWeight(1);
      ellipse(this.sender.x, this.sender.y, 16);
    }
  }


  feedforward(value){
    this.output = value * this.weight;
    this.sender = this.a.position.copy();
    this.sending = true;
  }

  update() {
    if(this.sending){
      this.sender.x = lerp(this.sender.x, this.b.position.x, 0.1);
      this.sender.y = lerp(this.sender.y, this.b.position.y, 0.1);

      let d = p5.Vector.dist(this.sender, this.b.position);

      if(d < 1){
        this.b.feedforward(this.output);
        this.sending = false;
      }
    }
  }
}
