-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
355 lines (316 loc) · 13.1 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
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>2D Ball Collision Physics Simulator</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css"
integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
/* Chrome, Safari, Edge, Opera */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
#textBox {
z-index: 1000;
}
/* Firefox */
/* input[type=number] {
-moz-appearance: textfield;
}
*/
canvas {
width: 100%;
/* height: 100%; */
}
</style>
<body onload="init()">
<div class="bg-gray-100 lg:p-10 items-center justify-center min-h-screen">
<div class="flex flex-col bg-white px-5 rounded min-w-screen shadow-lg flex">
<div class="w-full">
<!-- <div class="mr-0"> -->
<h1 class="text-2xl font-bold mb-4">2D Ball Elastic Collision Physics Simulator</h1>
<a href="https://github.com/rachancheet/2d_engine">Github</a>
<!-- </div> -->
<div class=" mt-4 mb-4 w-full">
<canvas onload="init()" width="900" height="400" id="canvas"></canvas>
</div>
<div class="flex flex-col space-y-4 mb-4">
<div class="flex lg:flex-row flex-col">
<div class="lg:flex lg:flex-col lg:space-y-4">
<button onclick="start()" class="ml-10 p-2 bg-green-500 text-white rounded">
Start
</button>
<button onclick="stop_()" class="ml-10 p-2 bg-red-500 text-white rounded">
Stop
</button>
<button onclick="step()" class="ml-10 p-2 bg-blue-500 text-white rounded">
Step
(SpaceBar)
<button onclick="demo()" class="ml-10 p-2 bg-blue-500 text-white rounded">
demo
</button>
<button onclick="pls_show_grid()" class="ml-10 p-2 bg-blue-500 text-white rounded">
Collision grid
</button>
</div>
<div class="flex lg:flex-row flex-col lg:space-x-10 lg:ml-20 mb-10 align-items ">
<!-- BALL -->
<div class="w-full">
<form onsubmit="addball(event)">
<div class="flex flex-row w-full mb-5 h-full ">
<div class="p-8 bg-white w-full rounded shadow-lg">
<h1 class="text-2xl font-bold mb-4">Ball Dimensions</h1>
<div class="flex flex-col space-y-2">
<label for="vector-input" class="font-medium text-xl">Enter Initial
Position:</label>
<div class="flex items-center space-x-2">
<span class="text-xl">(</span>
<input required type="number" id="x" class="p-2 border rounded w-20"
value="200" placeholder="X">
<span class="text-xl">,</span>
<input required type="number" id="y" class="p-2 border rounded w-20"
value="200" placeholder="Y">
<span class="text-xl">)</span>
</div>
<div class="flex flex-col">
<label for="ball-color" class="font-medium">Ball Color</label>
<input required value="#FFC0CB" type="color" id="color"
class="p-2 border rounded">
</div>
<div class="flex flex-col">
<label for="ball-radius" class="font-medium">Ball Radius</label>
<input value="15" required type="number" required id="radius"
class="p-2 border rounded w-48">
</div>
<label for="vector-input" class="font-medium text-xl">Enter Initial
Velocity:</label>
<div class="flex items-center mb-9 space-x-2">
<span class="text-xl">(</span>
<input value="1" required type="number" id="vx"
class="p-2 border rounded w-20" placeholder="X">
<span class="text-xl">,</span>
<input value="4" required type="number" id="vy"
class="p-2 border rounded w-20" placeholder="Y">
<span class="text-xl">)</span>
</div>
<div class="flex flex-row mt-10 items-center align-items space-x-0">
<label for="vector-input" class="font-medium text-xl">Gravity
:</label>
<input checked type="checkbox" id="gravity"
class="pt-10 align-items border rounded w-10">
</div>
</div>
<div class="m-5">
<button id="add-ball"
class="p-5 w-full bg-green-500 h-full text-white rounded">
<i class="fa-solid fa-circle-plus fa-2xl"></i>
</button>
</div>
</div>
</div>
</form>
</div>
<div class="w-full">
<!-- BALL -->
<form onsubmit="addline(event)">
<div class="flex flex-row w-full mb-5 h-full ">
<div class="p-8 bg-white w-full rounded shadow-lg">
<h1 class="text-2xl font-bold mb-4">Line Dimensions</h1>
<div class="flex flex-col space-y-2">
<label for="vector-input" class="font-medium text-xl">Enter Start
Position:</label>
<div class="flex items-center space-x-2">
<span class="text-xl">(</span>
<input type="number" id="Sx" class="p-2 border rounded w-20"
placeholder="X">
<span class="text-xl">,</span>
<input required type="number" id="Sy"
class="p-2 border rounded w-20" placeholder="Y">
<span class="text-xl">)</span>
</div>
<label for="vector-input" class="font-medium text-xl">Enter End
Position:</label>
<div class="flex items-center space-x-2">
<span class="text-xl">(</span>
<input required type="number" id="Ex"
class="p-2 border rounded w-20" placeholder="X">
<span class="text-xl">,</span>
<input required type="number" id="Ey"
class="p-2 border rounded w-20" placeholder="Y">
<span class="text-xl">)</span>
</div>
<div class="flex flex-col">
<label for="ball-color" class="font-medium">Line Color</label>
<input required type="color" id="color" class="p-2 border rounded">
</div>
</div>
<div class="m-5">
<button id="add-ball"
class="w-full p-5 bg-green-500 h-full text-white rounded">
<i class="fa-solid fa-circle-plus fa-2xl"></i>
</button>
</div>
</div>
</div>
</form>
</div>
<!-- <div class="flex flex-col h-[25rem] ">
<h2 class="text-xl font-bold mb-4">Elements</h2>
<ul id="elements-list" class="space-y-2 overflow-y-scroll">
sakldfjasl
</ul>
</div> -->
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<script type="application/javascript" src="event_handlers.js">
</script>
<script type="application/javascript" src="helper_functions.js">
</script>
<script type="application/javascript" src="line_thing.js">
</script>
<script type="application/javascript" src="circle_thing.js"> </script>
<script type="application/javascript" src="grid.js"> </script>
<script type="application/javascript" src="./app.js"></script>
<script type="application/javascript" src="./draw.js"> </script>
<!-- <script>
const elementsList = document.getElementById('elements-list');
function createElementItem(type, attributes, index) {
const item = document.createElement('li');
item.className = 'p-2 border rounded flex justify-between items-center';
item.innerHTML = `
<div>
<span class="font-bold">${type}</span>: ${attributes}
</div>
<button class="delete-element p-2 bg-red-500 text-white rounded" data-index="${index}">Delete</button>
`;
return item;
}
document.getElementById('add-line').addEventListener('click', () => {
const startX = document.getElementById('line-start-x').value;
const startY = document.getElementById('line-start-y').value;
const endX = document.getElementById('line-end-x').value;
const endY = document.getElementById('line-end-y').value;
const color = document.getElementById('line-color').value;
const attributes = `(${startX}, ${startY}) to (${endX}, ${endY}), Color: ${color}`;
const index = elementsList.children.length;
// new line_thing([star, d], [width - d, d], "white");
const item = createElementItem('Line', attributes, index);
elementsList.appendChild(item);
});
document.getElementById('add-ball').addEventListener('click', () => {
const radius = document.getElementById('ball-radius').value;
const color = document.getElementById('ball-color').value;
const startX = document.getElementById('ball-start-x').value;
const startY = document.getElementById('ball-start-y').value;
const attributes = `Radius: ${radius}, Color: ${color}, Position: (${startX}, ${startY})`;
const index = elementsList.children.length;
new circle_thing(startX, startY, radius, color, [-6, 6], [], true);
const item = createElementItem('Ball', attributes, index);
elementsList.appendChild(item);
});
elementsList.addEventListener('click', (event) => {
if (event.target.classList.contains('delete-element')) {
const index = event.target.getAttribute('data-index');
elementsList.removeChild(elementsList.children[index]);
}
});
</script> -->
</html>
<!-- <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>2D Ball Collision Physics Simulator</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 flex items-center justify-center min-h-screen">
<div class="container mx-auto p-4 bg-white rounded shadow-lg">
<h1 class="text-2xl font-bold mb-4">2D Ball Collision Physics Simulator</h1>
<div class="mb-4">
<canvas id="simulationCanvas" width="800" height="600" class="border"></canvas>
</div>
<div class="flex flex-col space-y-4 mb-4">
<div class="flex space-x-4">
<div class="flex flex-col">
<label for="line-start-x" class="font-medium">Line Start X</label>
<input type="number" id="line-start-x" class="p-2 border rounded">
</div>
<div class="flex flex-col">
<label for="line-start-y" class="font-medium">Line Start Y</label>
<input type="number" id="line-start-y" class="p-2 border rounded">
</div>
<div class="flex flex-col">
<label for="line-end-x" class="font-medium">Line End X</label>
<input type="number" id="line-end-x" class="p-2 border rounded">
</div>
<div class="flex flex-col">
<label for="line-end-y" class="font-medium">Line End Y</label>
<input type="number" id="line-end-y" class="p-2 border rounded">
</div>
<div class="flex flex-col">
<label for="line-color" class="font-medium">Line Color</label>
<input type="color" id="line-color" class="p-2 border rounded">
</div>
<button id="add-line" class="p-2 bg-blue-500 text-white rounded">Add Line</button>
</div>
<div class="flex space-x-4">
<div class="flex flex-col">
<label for="ball-radius" class="font-medium">Ball Radius</label>
<input type="number" id="ball-radius" class="p-2 border rounded">
</div>
<div class="flex flex-col">
<label for="ball-color" class="font-medium">Ball Color</label>
<input type="color" id="ball-color" class="p-2 border rounded">
</div>
<div class="flex flex-col">
<label for="ball-start-x" class="font-medium">Start X</label>
<input type="number" id="ball-start-x" class="p-2 border rounded">
</div>
<div class="flex flex-col">
<label for="ball-start-y" class="font-medium">Start Y</label>
<input type="number" id="ball-start-y" class="p-2 border rounded">
</div>
<button id="add-ball" class="p-2 bg-green-500 text-white rounded">Add Ball</button>
</div>
</div>
</div>
<script>
const canvas = document.getElementById('simulationCanvas');
const ctx = canvas.getContext('2d');
document.getElementById('add-line').addEventListener('click', () => {
const startX = parseInt(document.getElementById('line-start-x').value);
const startY = parseInt(document.getElementById('line-start-y').value);
const endX = parseInt(document.getElementById('line-end-x').value);
const endY = parseInt(document.getElementById('line-end-y').value);
const color = document.getElementById('line-color').value;
ctx.strokeStyle = color;
ctx.beginPath();
ctx.moveTo(startX, startY);
ctx.lineTo(endX, endY);
ctx.stroke();
});
document.getElementById('add-ball').addEventListener('click', () => {
const radius = parseInt(document.getElementById('ball-radius').value);
const color = document.getElementById('ball-color').value;
const startX = parseInt(document.getElementById('ball-start-x').value);
const startY = parseInt(document.getElementById('ball-start-y').value);
ctx.fillStyle = color;
ctx.beginPath();
ctx.arc(startX, startY, radius, 0, Math.PI * 2);
ctx.fill();
});
</script>
</body>
</html> -->