-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.js
91 lines (79 loc) · 2.02 KB
/
ui.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
let alignSlider, cohesionSlider, separationSlider, numBoids, perceptSlider;
let alignText, cohesionText, separationText, perceptText, boidText, count, fps;
let checkbox, showQtree, showPercept, button, record;
let bounding, boundingTitle, qtreeCapacity, qtreeCapacityTitle;
let sourceCode;
function setupUI() {
// Check Boxes
enableQtree = select('#enableQtree');
enableQtree.changed(toOptimize);
showQtree = select('#showQtree');
showQtree.changed(displayQtree);
showPercept = select('#showPercept');
showPercept.changed(displayPercept);
// Radio Buttons
bounding = document.getElementsByName('boundaryType');
qtreeCapacity = document.getElementsByName('qtreeCapacity');
// Normal Buttons
button = select('#toggleLoop');
button.mousePressed(toggleLoop);
record = select('#record');
record.mousePressed(toggleRecord);
// Sliders
numBoids = select('#numBoids');
alignSlider = select('#alignSlider');
cohesionSlider = select('#cohesionSlider');
separationSlider = select('#separationSlider');
perceptSlider = select('#perceptionRadius');
}
function toOptimize() {
if (this.checked()) {
return (optimize = true);
} else {
return (optimize = false);
}
}
function displayQtree() {
if (this.checked()) {
return (showQtree = true);
} else {
return (showQtree = false);
}
}
function displayPercept() {
if (this.checked()) {
return (preceptShow = true);
} else {
return (preceptShow = false);
}
}
function toggleLoop() {
if (isLoop) {
noLoop();
isLoop = false;
} else {
loop();
isLoop = true;
}
}
function toggleRecord() {
if (isRecording) {
isRecording = false;
save = true;
} else {
isRecording = true;
save = false;
}
}
function numOfBoids() {
let diff;
if (flock.length > numBoids.value()) {
diff = flock.length - numBoids.value();
flock.splice(0, diff);
} else if (flock.length < numBoids.value()) {
diff = numBoids.value() - flock.length;
for (let i = 0; i < diff; i++) {
flock.push(new Boid());
}
}
}