-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButtons.js
268 lines (237 loc) · 7.35 KB
/
Buttons.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
//When these are true, the related inputfield is valid.
var rateBool = true, particlesBool = true, particleSizeBool = true;
// Maximums for the input fields.
var maxEmissionRate = 2500;
var maxParticleSize = 25;
var maxParticlesNumber = 10000;
// Selector for the alert dialog.
var alert = $('#alert');
// Selectors for the emission rate button/input
var rateButton = $('#rateButton');
var rateInput = $('#rateInput');
// Selectors for the maximum particles button/input
var particlesButton = $('#particlesButton');
var particlesInput = $('#particlesInput');
// Selectors for the particle size button/input
var particleSizeButton = $('#particleSizeButton');
var particleSizeInput = $('#particleSizeInput');
// This is the functino that pauses and plays the simulation.
function playPause() {
play = !play;
if(play) {
loop();
}
}
// Intro snow button should start the snow simulation and disable to snow button.
$('#startSnowButton').on('click', function() {
toggleIntro(snow());
snowButton.prop('disabled','true');
setDefaults();
});
// Intro rain button should start the rain simulation and disable to rain button.
$('#startRainButton').on('click', function() {
toggleIntro(rain());
rainButton.prop('disabled','true');
setDefaults();
});
// Intro rain button should start the rain simulation and disable to rain button.
// Also disable the wind button because the insect simulation has no wind.
$('#startInsectButton').on('click', function() {
toggleIntro(insect());
insectButton.prop('disabled','true');
windToggleButton.prop('disabled','true');
setDefaults();
});
// Stops and starts the animation.
$('#playPauseButton').on('click', function() {
playPause();
});
//Checks if the alert dialog can be removed.
//If all of the input fields are valid, then remove the alert.
//If one of them is invalid then keep the alert.
function checkAlert() {
if(rateBool && particlesBool && particleSizeBool) {
alert.css('display','none');
}
else {
alert.css('display','block');
}
}
// Code involving the emission rate input.
rateButton.on('click', function() {
var rate = rateInput.val();
if(rate >= 1 && rate <= maxEmissionRate) {
emissionRate = rate;
rateBool = true;
rateButton.removeClass('alert-danger');
}
else {
rateBool = false;
rateButton.addClass('alert-danger');
}
checkAlert();
});
//Bind the enter button RATE
$(function(){
rateInput.keypress(function(e){
if(e.which == 13) {
var rate = rateInput.val();
if(rate >= 1 && rate <= maxEmissionRate) {
emissionRate = rate;
rateBool = true;
rateButton.removeClass('alert-danger');
}
else {
rateBool = false;
rateButton.addClass('alert-danger');
}
checkAlert();
}
});
});
// Code involving maximum particles input.
particlesButton.on('click', function() {
var num = particlesInput.val();
if(num >= 1 && num <= maxParticlesNumber) {
maxParticles = num;
particlesBool = true;
particlesButton.removeClass('alert-danger');
}
else {
particlesBool = false;
particlesButton.addClass('alert-danger');
}
checkAlert();
});
//Bind the enter button max PARTICLES
$(function(){
particlesInput.keypress(function(e){
if(e.which == 13) {
var num = particlesInput.val();
if(num >= 1 && num <= maxParticlesNumber) {
maxParticles = num;
particlesBool = true;
particlesButton.removeClass('alert-danger');
}
else {
particlesBool = false;
particlesButton.addClass('alert-danger');
}
checkAlert();
}
});
});
//Particle size button
particleSizeButton.on('click', function() {
var num = particleSizeInput.val();
if(num >= 1 && num <= maxParticleSize) {
particleSize = num;
particleSizeBool = true;
particleSizeButton.removeClass('alert-danger');
}
else {
particleSizeBool = false;
particleSizeButton.addClass('alert-danger');
}
checkAlert();
});
// Particle size button on ENTER
$(function(){
particleSizeInput.keypress(function(e){
if(e.which == 13) {
var num = particleSizeInput.val();
if(num >= 1 && num <= maxParticleSize) {
particleSize = num;
particleSizeBool = true;
particleSizeButton.removeClass('alert-danger');
}
else {
particleSizeBool = false;
particleSizeButton.addClass('alert-danger');
}
checkAlert();
}
});
});
// Sets the places holders for the input fields.
function setRateInputPlaceholder() {
rateInput.prop('placeholder','between 1 and ' + maxEmissionRate + ' (inclusive)');
}
function setParticlesInputPlaceholder() {
particlesInput.prop('placeholder','between 1 and ' + maxParticlesNumber + ' (inclusive)');
}
function setMaxParticleSizePlaceholder() {
particleSizeInput.prop('placeholder','between 1 and ' + maxParticleSize + ' (inclusive)');
}
function setDefaults() {
// Sets the placeholder text of the inputs.
setRateInputPlaceholder();
setParticlesInputPlaceholder();
setMaxParticleSizePlaceholder();
// Sets the inputs' default values to the default values.
rateInput.val(emissionRate);
particlesInput.val(maxParticles);
particleSizeInput.val(particleSize);
// Sets the default text for the wind dialog button.
if(windOn) {
windToggleButton.html('Wind: Enabled');
}
else {
windToggleButton.html('Wind: Disabled');
}
}
// Clears the simulation of old particles, emitters, and fields.
function clearArrays() {
particles = []; //Clears the particle Array.
emitters = []; //Clears the emitters Array.
fields = []; //Clears the fields Array.
}
var rainButton = $('#rainButton');// Selector for the rain button
var snowButton = $('#snowButton');// Selector for the snowButton
var insectButton = $('#insectButton');// Selector for the insectButton
// Changes the simulation to rain.
rainButton.on('click', function() {
playPause();// Stop all other simulations.
clearArrays();// Clear simulation.
snowButton.removeAttr('disabled');
rainButton.prop('disabled','true');
insectButton.removeAttr('disabled');
windToggleButton.removeAttr('disabled');
rain();// Start the rain simluation.
setDefaults();
});
snowButton.on('click', function() {
playPause();// Stop all other simulations.
clearArrays();// Clear simulation.
snowButton.prop('disabled','true');
rainButton.removeAttr('disabled');
insectButton.removeAttr('disabled');
windToggleButton.removeAttr('disabled');
snow();// Start the snow simluation.
setDefaults();
});
insectButton.on('click', function() {
playPause();// Stop all other simulations.
clearArrays();// Clear simulation.
windToggleButton.prop('disabled','true');
insectButton.prop('disabled','true');// Make the insect button unclickable
rainButton.removeAttr('disabled');
snowButton.removeAttr('disabled');
insect();// Start the insect simluation.
setDefaults();
});
var windToggleButton = $('#windToggleButton');// Selector for the Wind toggle Button
// This toggles the wind and changes the button text whenever the button is clicked.
windToggleButton.on('click', function() {
if(insectButton.prop('disabled') === true) {
windToggleButton.prop('disabled','true');
return;
}
windOn = !windOn;
if(windOn) {
windToggleButton.html('Wind: Enabled');
}
else {
windToggleButton.html('Wind: Disabled');
}
});