-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
145 lines (134 loc) · 6.69 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="styles.css">
<script src="events.js" defer></script>
<script src="doublependulum.js"></script>
<title>JS Double Pendulum</title>
</head>
<body>
<div id="flex-space">
<div id="output">
<canvas id="myCanvas" width="1000" height="1000"></canvas>
</div>
<div id="controllers">
<h1>JS Double Pendulum</h1>
<div id="buttons">
<div id="topbuttons">
<button type="button" id="startbtn" onclick="start()">Start</button>
<button type="button" id="stopbtn" onclick="stop()" disabled>Stop</button>
</div>
<button type="button" id="logbtn" onclick="printlog()">Print state to console</button>
</div>
<div id="sliders">
<hr>
<h3 class="sectiontitle">Global:</h3>
<div class="sliderdiv">
<label for="slidergravity">Gravity:</label>
<input type="range" min="0" max="10" id="slidergravity" class="slider" step="0.1">
<p class="value" id="valuegravity"></p>
</div>
<div class="sliderdiv">
<label for="sliderdamping">Retention:</label>
<input type="range" min="0.95" max="1" id="sliderdamping" class="slider" step="0.000001">
<p class="value" id="valuedamping"></p>
</div>
<hr>
<h3 class="sectiontitle">First Pendulum:</h3>
<div id="slidersone">
<div class="sliderdiv">
<label for="sliderangleone">Angle:</label>
<input type="range" min="-3.14159265358" max="3.14159265359" id="sliderangleone" class="slider" step="0.01">
<p class="value" id="valueangleone"></p>
</div>
<div class="sliderdiv">
<label for="sliderlengthone">Length:</label>
<input type="range" min="5" max="300" id="sliderlengthone" class="slider" step="1">
<p class="value" id="valuelengthone"></p>
</div>
<div class="sliderdiv">
<label for="slidermassone">Mass:</label>
<input type="range" min="1" max="50" id="slidermassone" class="slider" step="1">
<p class="value" id="valuemassone"></p>
</div>
</div>
<hr>
<h3 class="sectiontitle">Second Pendulum:</h3>
<div id="sliderstwo">
<div class="sliderdiv">
<label for="sliderangletwo">Angle:</label>
<input type="range" min="-3.14159265358" max="3.14159265359" id="sliderangletwo" class="slider" step="0.01">
<p class="value" id="valueangletwo"></p>
</div>
<div class="sliderdiv">
<label for="sliderlengthtwo">Length:</label>
<input type="range" min="5" max="300" id="sliderlengthtwo" class="slider" step="1">
<p class="value" id="valuelengthtwo"></p>
</div>
<div class="sliderdiv">
<label for="slidermasstwo">Mass:</label>
<input type="range" min="1" max="50" id="slidermasstwo" class="slider" step="1">
<p class="value" id="valuemasstwo"></p>
</div>
</div>
<hr>
</div>
</div>
</div>
<script>
//setup canvasses - PROGRAM ENTRY POINT HERE
var canv = document.getElementById("myCanvas");
var ctx = canv.getContext("2d");
// Read sliders into variables for conveniance
var slidergravity = document.getElementById("slidergravity");
var valuegravity = document.getElementById("valuegravity");
var sliderdamping = document.getElementById("sliderdamping");
var valuedamping = document.getElementById("valuedamping");
var sliderangleone = document.getElementById("sliderangleone");
var valueangleone = document.getElementById("valueangleone");
var sliderangletwo = document.getElementById("sliderangletwo");
var valueangletwo = document.getElementById("valueangletwo");
var sliderlengthone = document.getElementById("sliderlengthone");
var valuelengthone = document.getElementById("valuelengthone");
var sliderlengthtwo = document.getElementById("sliderlengthtwo");
var valuelengthtwo = document.getElementById("valuelengthtwo");
var slidermassone = document.getElementById("slidermassone");
var valuemassone = document.getElementById("valuemassone");
var slidermasstwo = document.getElementById("slidermasstwo");
var valuemasstwo = document.getElementById("valuemasstwo");
// Initialise variables
var trace = [];
var G = 1;
var D = 1;
const ox = 0;
const oy = 0;
var x1; // Bob posn
var y1; // Bob posn
var p1r = 240; // Pendulus length
var p1m = 17; // Bob mass
var p1theta = -Math.PI / 2; // Angle from vertically down
var p1v = 0; // Angular velocity
var p1a = 0; // Angular accn
var x2;
var y2;
var p2r = 240;
var p2m = 10;
var p2theta = -Math.PI / 4;
var p2v = 0;
var p2a = 0;
var traceGradient = buildGradient();
// Import variable values from above into displayed sliders
slidergravity.value = G;
sliderdamping.value = D;
sliderangleone.value = (p1theta % Math.PI);
sliderangletwo.value = (p2theta % Math.PI);
sliderlengthone.value = p1r;
sliderlengthtwo.value = p2r;
slidermassone.value = p1m;
slidermasstwo.value = p2m;
updateLabels()
draw();
</script>
</body>