forked from nxxcxx/Neural-Network
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignal.js
55 lines (42 loc) · 1.42 KB
/
signal.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
50
51
52
53
54
55
// Signal extends THREE.Vector3 ----------------------------------------------------------------
function Signal( particlePool, minSpeed, maxSpeed ) {
this.minSpeed = minSpeed;
this.maxSpeed = maxSpeed;
this.speed = THREE.Math.randFloat( this.minSpeed, this.maxSpeed );
this.alive = true;
this.t = null;
this.startingPoint = null;
this.axon = null;
this.particle = particlePool.getParticle();
THREE.Vector3.call( this );
}
Signal.prototype = Object.create( THREE.Vector3.prototype );
Signal.prototype.setConnection = function ( Connection ) {
this.startingPoint = Connection.startingPoint;
this.axon = Connection.axon;
if ( this.startingPoint === 'A' ) this.t = 0;
else if ( this.startingPoint === 'B' ) this.t = 1;
};
Signal.prototype.travel = function ( deltaTime ) {
var pos;
if ( this.startingPoint === 'A' ) {
this.t += this.speed * deltaTime;
if ( this.t >= 1 ) {
this.t = 1;
this.alive = false;
this.axon.neuronB.receivedSignal = true;
this.axon.neuronB.prevReleaseAxon = this.axon;
}
} else if ( this.startingPoint === 'B' ) {
this.t -= this.speed * deltaTime;
if ( this.t <= 0 ) {
this.t = 0;
this.alive = false;
this.axon.neuronA.receivedSignal = true;
this.axon.neuronA.prevReleaseAxon = this.axon;
}
}
pos = this.axon.getPoint( this.t );
// pos = this.axon.getPointAt(this.t); // uniform point distribution but slower calculation
this.particle.set( pos.x, pos.y, pos.z );
};