-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrajectories.js
63 lines (49 loc) · 1.65 KB
/
trajectories.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
56
57
58
59
60
61
62
63
// Store the trajectories of the two galaxy cores
/**
* Store initial trajectories
*
* @return {object} Trajectory state object
*/
export function init(positions, size=10000) {
let trajectories1 = Array(size * 3).fill(0);
let trajectories2 = Array(size * 3).fill(0);
// Store positions of the two galaxy cores
// ------
trajectories1[0] = positions[0];
trajectories1[1] = positions[1];
trajectories1[2] = positions[2];
trajectories2[0] = positions[3];
trajectories2[1] = positions[4];
trajectories2[2] = positions[5];
let state = {
trajectories: [trajectories1, trajectories2],
// Number of positions for each galaxy core stored in `trajectories`
points: 1
};
return state;
}
/**
* Add the positions of the two galaxy cores to the trajectory arrays.
*/
export function update(state, positions) {
if (state.points == state.trajectories[0].length / 3) {
// Arrays are full, remove the first positions to make room for the new ones
state.trajectories[0].shift();
state.trajectories[0].shift();
state.trajectories[0].shift();
state.trajectories[1].shift();
state.trajectories[1].shift();
state.trajectories[1].shift();
state.points -= 1;
}
// Store positions of the two galaxy cores
// ------
state.trajectories[0][state.points * 3] = positions[0];
state.trajectories[0][state.points * 3 + 1] = positions[1];
state.trajectories[0][state.points * 3 + 2] = positions[2];
state.trajectories[1][state.points * 3] = positions[3];
state.trajectories[1][state.points * 3 + 1] = positions[4];
state.trajectories[1][state.points * 3 + 2] = positions[5];
state.points += 1;
return state;
}