-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneuron.js
More file actions
32 lines (28 loc) · 871 Bytes
/
neuron.js
File metadata and controls
32 lines (28 loc) · 871 Bytes
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
class Neuron {
constructor(x, y, axonNumber) {
this.power = 0.002;
this.position = createVector(x, y);
this.axons = [];
for (let i = 0; i < axonNumber; i++) {
this.axons.push(new Axon(this.position.x, this.position.y));
}
}
display() {
stroke(255);
strokeWeight(2);
fill(127);
ellipse(this.position.x, this.position.y, 32, 32);
for (let i = 0; i < this.axons.length; i++) {
this.axons[i].display();
this.axons[i].update();
}
ps.addParticle(this.position.x, this.position.y);
}
attract(axon) {
let dir = p5.Vector.sub(this.position, axon.positionEnd); // Calculate direction of force
//dir.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction)
let force = this.power;
dir = p5.Vector.mult(dir, force);
return dir;
}
};