forked from nathangeffen/space-travel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspacestart.js
60 lines (49 loc) · 1.67 KB
/
spacestart.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
/*
This integrates the calculation and animation code. It hooks the
run, calculate and clear buttons to their event code.
*/
var animation = new Animation('svg-viewer', 0, 800);
var traveler = new Traveler();
runAnimation = function()
{
clearErrorMessage();
iterations = document.getElementById('iterations').value;
if (!isNumber(iterations) ||
!(iterations > 0 && iterations < 10000))
iterations = 200;
milliseconds = document.getElementById('milliseconds').value;
if (!isNumber(milliseconds) ||
!(milliseconds > 0 && milliseconds < 2000))
milliseconds = 50;
if (traveler.fields['observer_time'].value &&
traveler.fields['distance'].value &&
traveler.fields['acceleration'].value) {
animation.run(traveler.fields['observer_time'].value,
traveler.fields['traveler_time'].value,
traveler.fields['distance'].value,
traveler.fields['acceleration'].value,
iterations,
milliseconds);
} else {
setErrorMessage("Please first calculate or set the distance and velocity.");
}
}
calculate = function()
{
traveler.calculate();
if (traveler.fields['distance'].value &&
traveler.fields['acceleration'].value) {
document.getElementById("animate-button").disabled = false;
} else {
document.getElementById("animate-button").disabled = true;
}
}
clearFields = function()
{
traveler.clear();
document.getElementById("animate-button").disabled = true;
}
window.onload = function() {
animation.initialize();
traveler.processOutput();
};