-
Notifications
You must be signed in to change notification settings - Fork 1
/
actionPotential.js
49 lines (40 loc) · 1.34 KB
/
actionPotential.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class ActionPotential {
constructor(sourceNeuron, destinyNeuron, skew, id, charge, neuronSize) {
this.sourceNeuron = sourceNeuron;
this.destinyNeuron = destinyNeuron;
this.size = neuronSize/sketchOptions.actionPotentialDivisor;
this.id = id;
this.charge = charge;
skew -= this.size/2;
this.x = sourceNeuron.x + skew;
this.y = sourceNeuron.y + skew;
this.destinyX = destinyNeuron.x + skew;
this.destinyY = destinyNeuron.y + skew;
let length = Math.sqrt(Math.pow(this.destinyX-this.x, 2) + Math.pow(this.destinyY-this.y, 2));
this.xSlope = (this.destinyX-this.x)/length * 2;
this.ySlope = (this.destinyY-this.y)/length * 2;
this.maxSteps = this.xSlope === 0 ? (this.destinyY-this.y)/this.ySlope : (this.destinyX-this.x)/this.xSlope;
this.steps = 0;
}
display() {
noStroke();
this.charge > 0 ? fill(255) : fill(0);
rect(this.x, this.y, this.size, this.size);
this.move();
}
move() {
this.x += this.xSlope;
this.y += this.ySlope;
this.steps++;
if (this.steps >= this.maxSteps) {
this.destinyNeuron.addCharge(this.charge);
delete actionPotentialList[`${this.id}`];
}
}
static displayAllActionPotentials() {
let keys = _.keys(actionPotentialList);
for(var i=0; i<keys.length;i++) {
actionPotentialList[keys[i]].display();
}
}
}