AARIFSHABIR commited on
Commit
3e6997b
·
verified ·
1 Parent(s): cbad812

Make virtual physics app prepared by IITians in India - Initial Deployment

Browse files
Files changed (3) hide show
  1. README.md +7 -5
  2. index.html +633 -19
  3. prompts.txt +1 -0
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Virtual Physics
3
- emoji: 🦀
4
- colorFrom: indigo
5
- colorTo: blue
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: virtual-physics
3
+ emoji: 🐳
4
+ colorFrom: pink
5
+ colorTo: purple
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,633 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Virtual Physics Lab | Developed by IITians</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
9
+ <style>
10
+ .experiment-area {
11
+ background-image: linear-gradient(to right, #f3f4f6, #e5e7eb);
12
+ box-shadow: inset 0 0 20px rgba(0,0,0,0.1);
13
+ position: relative;
14
+ overflow: hidden;
15
+ }
16
+ .ball {
17
+ position: absolute;
18
+ border-radius: 50%;
19
+ cursor: pointer;
20
+ transition: transform 0.1s;
21
+ box-shadow: 0 5px 15px rgba(0,0,0,0.2);
22
+ }
23
+ .spring {
24
+ position: absolute;
25
+ background-color: #9ca3af;
26
+ border-radius: 5px;
27
+ }
28
+ .pendulum-string {
29
+ position: absolute;
30
+ background-color: #6b7280;
31
+ }
32
+ .pendulum-bob {
33
+ position: absolute;
34
+ border-radius: 50%;
35
+ background-color: #3b82f6;
36
+ box-shadow: 0 5px 15px rgba(0,0,0,0.2);
37
+ }
38
+ @keyframes pendulumSwing {
39
+ 0% { transform: rotate(-30deg); }
40
+ 50% { transform: rotate(30deg); }
41
+ 100% { transform: rotate(-30deg); }
42
+ }
43
+ @keyframes gravityFall {
44
+ 0% { top: 50px; }
45
+ 100% { top: 350px; }
46
+ }
47
+ </style>
48
+ </head>
49
+ <body class="bg-gray-50 font-sans">
50
+ <header class="bg-gradient-to-r from-blue-600 to-indigo-800 text-white py-4 px-6 shadow-lg">
51
+ <div class="container mx-auto flex justify-between items-center">
52
+ <div class="flex items-center space-x-2">
53
+ <i class="fas fa-atom text-3xl"></i>
54
+ <h1 class="text-2xl font-bold">Virtual Physics Lab</h1>
55
+ </div>
56
+ <div class="hidden md:flex items-center space-x-4">
57
+ <span class="bg-yellow-400 text-gray-800 px-3 py-1 rounded-full text-sm font-bold">
58
+ Developed by IITians
59
+ </span>
60
+ <button class="bg-white text-indigo-700 px-4 py-2 rounded-full font-medium hover:bg-blue-50 transition">
61
+ Try Premium
62
+ </button>
63
+ </div>
64
+ <button class="md:hidden text-2xl">
65
+ <i class="fas fa-bars"></i>
66
+ </button>
67
+ </div>
68
+ </header>
69
+
70
+ <main class="container mx-auto px-4 py-8">
71
+ <div class="flex flex-col lg:flex-row gap-8">
72
+ <div class="lg:w-1/4 bg-white rounded-xl shadow-md overflow-hidden">
73
+ <div class="bg-indigo-600 text-white px-4 py-3">
74
+ <h2 class="text-lg font-semibold flex items-center">
75
+ <i class="fas fa-flask mr-2"></i> Experiments
76
+ </h2>
77
+ </div>
78
+ <div class="p-4">
79
+ <ul class="space-y-2">
80
+ <li>
81
+ <button onclick="setupExperiment('projectile')" class="w-full text-left px-4 py-3 bg-blue-50 rounded-lg hover:bg-blue-100 transition flex items-center">
82
+ <i class="fas fa-basketball-ball mr-3 text-blue-600"></i>
83
+ Projectile Motion
84
+ </button>
85
+ </li>
86
+ <li>
87
+ <button onclick="setupExperiment('pendulum')" class="w-full text-left px-4 py-3 bg-blue-50 rounded-lg hover:bg-blue-100 transition flex items-center">
88
+ <i class="fas fa-clock mr-3 text-green-600"></i>
89
+ Simple Pendulum
90
+ </button>
91
+ </li>
92
+ <li>
93
+ <button onclick="setupExperiment('spring')" class="w-full text-left px-4 py-3 bg-blue-50 rounded-lg hover:bg-blue-100 transition flex items-center">
94
+ <i class="fas fa-expand mr-3 text-yellow-600"></i>
95
+ Spring Oscillator
96
+ </button>
97
+ </li>
98
+ <li>
99
+ <button onclick="setupExperiment('gravity')" class="w-full text-left px-4 py-3 bg-blue-50 rounded-lg hover:bg-blue-100 transition flex items-center">
100
+ <i class="fas fa-apple-alt mr-3 text-red-600"></i>
101
+ Free Fall (Gravity)
102
+ </button>
103
+ </li>
104
+ </ul>
105
+ </div>
106
+
107
+ <div class="border-t p-4 bg-gray-50">
108
+ <h3 class="font-medium mb-3 flex items-center">
109
+ <i class="fas fa-sliders-h mr-2"></i> Parameters
110
+ </h3>
111
+ <div id="parameters" class="space-y-4">
112
+ <div class="mb-3">
113
+ <label class="block text-sm font-medium text-gray-700 mb-1">Mass (kg)</label>
114
+ <input type="range" min="1" max="10" value="5" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer" id="massSlider">
115
+ <div class="flex justify-between text-xs text-gray-500 mt-1">
116
+ <span>1</span>
117
+ <span id="massValue">5</span>
118
+ <span>10</span>
119
+ </div>
120
+ </div>
121
+ <div class="mb-3">
122
+ <label class="block text-sm font-medium text-gray-700 mb-1">Angle (°)</label>
123
+ <input type="range" min="0" max="90" value="45" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer" id="angleSlider">
124
+ <div class="flex justify-between text-xs text-gray-500 mt-1">
125
+ <span>0</span>
126
+ <span id="angleValue">45</span>
127
+ <span>90</span>
128
+ </div>
129
+ </div>
130
+ <div class="pt-3">
131
+ <button onclick="startExperiment()" class="w-full bg-green-600 hover:bg-green-700 text-white py-2 px-4 rounded-lg font-medium flex items-center justify-center">
132
+ <i class="fas fa-play mr-2"></i> Start Simulation
133
+ </button>
134
+ </div>
135
+ </div>
136
+ </div>
137
+ </div>
138
+
139
+ <div class="lg:w-3/4">
140
+ <div class="bg-white rounded-xl shadow-md overflow-hidden">
141
+ <div class="bg-indigo-600 text-white px-4 py-3 flex justify-between items-center">
142
+ <h2 class="text-lg font-semibold">Simulation Area</h2>
143
+ <div>
144
+ <button onclick="resetExperiment()" class="bg-white text-indigo-700 px-3 py-1 rounded text-sm font-medium hover:bg-blue-50 transition">
145
+ <i class="fas fa-redo mr-1"></i> Reset
146
+ </button>
147
+ </div>
148
+ </div>
149
+ <div class="experiment-area h-96 md:h-[500px] relative" id="experimentArea">
150
+ <!-- Experiment will be rendered here -->
151
+ <div class="absolute inset-0 flex items-center justify-center">
152
+ <div class="text-center text-gray-400">
153
+ <i class="fas fa-mouse-pointer text-4xl mb-2"></i>
154
+ <p>Select an experiment from the left panel to begin</p>
155
+ </div>
156
+ </div>
157
+ </div>
158
+ </div>
159
+
160
+ <div class="mt-6 grid grid-cols-1 md:grid-cols-3 gap-4">
161
+ <div class="bg-white p-4 rounded-lg shadow">
162
+ <h3 class="font-medium text-gray-700 mb-2 flex items-center">
163
+ <i class="fas fa-chart-line text-blue-500 mr-2"></i> Real-time Values
164
+ </h3>
165
+ <div class="space-y-2 text-sm">
166
+ <div class="flex justify-between">
167
+ <span>Velocity:</span>
168
+ <span id="velocityValue" class="font-medium">0 m/s</span>
169
+ </div>
170
+ <div class="flex justify-between">
171
+ <span>Acceleration:</span>
172
+ <span id="accelerationValue" class="font-medium">0 m/s²</span>
173
+ </div>
174
+ <div class="flex justify-between">
175
+ <span>Force:</span>
176
+ <span id="forceValue" class="font-medium">0 N</span>
177
+ </div>
178
+ </div>
179
+ </div>
180
+ <div class="bg-white p-4 rounded-lg shadow">
181
+ <h3 class="font-medium text-gray-700 mb-2 flex items-center">
182
+ <i class="fas fa-info-circle text-green-500 mr-2"></i> Experiment Details
183
+ </h3>
184
+ <div id="experimentDesc" class="text-sm text-gray-600">
185
+ Select an experiment to see details
186
+ </div>
187
+ </div>
188
+ <div class="bg-white p-4 rounded-lg shadow">
189
+ <h3 class="font-medium text-gray-700 mb-2 flex items-center">
190
+ <i class="fas fa-book text-yellow-500 mr-2"></i> Key Concepts
191
+ </h3>
192
+ <ul id="keyConcepts" class="text-sm list-disc list-inside space-y-1 text-gray-600">
193
+ <li>Select an experiment first</li>
194
+ </ul>
195
+ </div>
196
+ </div>
197
+ </div>
198
+ </div>
199
+ </main>
200
+
201
+ <footer class="bg-gray-800 text-white py-8 px-6 mt-12">
202
+ <div class="container mx-auto">
203
+ <div class="flex flex-col md:flex-row justify-between items-center">
204
+ <div class="mb-4 md:mb-0">
205
+ <h3 class="text-xl font-bold flex items-center">
206
+ <i class="fas fa-atom mr-2"></i> Virtual Physics Lab
207
+ </h3>
208
+ <p class="text-gray-400 mt-1">Developed by IITians in India</p>
209
+ </div>
210
+ <div class="flex space-x-6">
211
+ <a href="#" class="hover:text-blue-300 transition">
212
+ <i class="fab fa-github text-2xl"></i>
213
+ </a>
214
+ <a href="#" class="hover:text-blue-400 transition">
215
+ <i class="fab fa-linkedin text-2xl"></i>
216
+ </a>
217
+ <a href="#" class="hover:text-red-400 transition">
218
+ <i class="fab fa-youtube text-2xl"></i>
219
+ </a>
220
+ </div>
221
+ </div>
222
+ <div class="border-t border-gray-700 mt-6 pt-6 text-center text-gray-400 text-sm">
223
+ <p>© 2023 Virtual Physics Lab. All rights reserved. | Designed as an educational tool by IIT graduates.</p>
224
+ </div>
225
+ </div>
226
+ </footer>
227
+
228
+ <script>
229
+ // Current experiment type
230
+ let currentExperiment = null;
231
+ let animationId = null;
232
+ let pendulumAngle = 30;
233
+ let pendulumDirection = 1;
234
+ let springPosition = 200;
235
+ let springDirection = 1;
236
+ let gravityPosition = 50;
237
+ let projectileX = 50;
238
+ let projectileY = 300;
239
+ let projectileVelocityX = 5;
240
+ let projectileVelocityY = -5;
241
+ let projectileGravity = 0.2;
242
+
243
+ // DOM elements
244
+ const experimentArea = document.getElementById('experimentArea');
245
+ const massSlider = document.getElementById('massSlider');
246
+ const massValue = document.getElementById('massValue');
247
+ const angleSlider = document.getElementById('angleSlider');
248
+ const angleValue = document.getElementById('angleValue');
249
+ const velocityValue = document.getElementById('velocityValue');
250
+ const accelerationValue = document.getElementById('accelerationValue');
251
+ const forceValue = document.getElementById('forceValue');
252
+ const experimentDesc = document.getElementById('experimentDesc');
253
+ const keyConcepts = document.getElementById('keyConcepts');
254
+
255
+ // Update slider values
256
+ massSlider.addEventListener('input', () => {
257
+ massValue.textContent = massSlider.value;
258
+ });
259
+
260
+ angleSlider.addEventListener('input', () => {
261
+ angleValue.textContent = angleSlider.value;
262
+ });
263
+
264
+ // Setup experiment
265
+ function setupExperiment(type) {
266
+ currentExperiment = type;
267
+ experimentArea.innerHTML = '';
268
+
269
+ // Clear any existing animations
270
+ if (animationId) {
271
+ cancelAnimationFrame(animationId);
272
+ animationId = null;
273
+ }
274
+
275
+ // Reset positions
276
+ pendulumAngle = 30;
277
+ springPosition = 200;
278
+ gravityPosition = 50;
279
+ projectileX = 50;
280
+ projectileY = 300;
281
+ projectileVelocityX = 5;
282
+ projectileVelocityY = -5;
283
+
284
+ // Setup based on experiment type
285
+ switch(type) {
286
+ case 'projectile':
287
+ setupProjectile();
288
+ experimentDesc.innerHTML = `
289
+ <p>Simulate the motion of a projectile under gravity, demonstrating how objects follow a parabolic trajectory when launched at an angle.</p>
290
+ `;
291
+ keyConcepts.innerHTML = `
292
+ <li>Parabolic trajectory</li>
293
+ <li>Horizontal motion is uniform</li>
294
+ <li>Vertical motion is accelerated</li>
295
+ <li>Independent x and y components</li>
296
+ `;
297
+ break;
298
+ case 'pendulum':
299
+ setupPendulum();
300
+ experimentDesc.innerHTML = `
301
+ <p>Explore simple harmonic motion with a pendulum, observing the relationship between length, gravity, and period of oscillation.</p>
302
+ `;
303
+ keyConcepts.innerHTML = `
304
+ <li>Simple harmonic motion</li>
305
+ <li>Period depends on length</li>
306
+ <li>Restoring force proportional to displacement</li>
307
+ <li>Energy conservation</li>
308
+ `;
309
+ break;
310
+ case 'spring':
311
+ setupSpring();
312
+ experimentDesc.innerHTML = `
313
+ <p>Visualize Hooke's Law in action with a spring-mass system, showing how the restoring force relates to displacement.</p>
314
+ `;
315
+ keyConcepts.innerHTML = `
316
+ <li>Hooke's Law (F = -kx)</li>
317
+ <li>Simple harmonic motion</li>
318
+ <li>Period depends on mass</li>
319
+ <li>Energy conservation</li>
320
+ `;
321
+ break;
322
+ case 'gravity':
323
+ setupGravity();
324
+ experimentDesc.innerHTML = `
325
+ <p>Demonstrate free fall under gravity, showing how all objects accelerate at the same rate regardless of mass in a vacuum.</p>
326
+ `;
327
+ keyConcepts.innerHTML = `
328
+ <li>Uniform acceleration (g = 9.8 m/s²)</li>
329
+ <li>Independent of mass</li>
330
+ <li>Potential to kinetic energy conversion</li>
331
+ <li>Equations of motion</li>
332
+ `;
333
+ break;
334
+ }
335
+ }
336
+
337
+ // Setup projectile experiment
338
+ function setupProjectile() {
339
+ // Add ground
340
+ const ground = document.createElement('div');
341
+ ground.className = 'absolute bottom-0 left-0 right-0 h-2 bg-green-700';
342
+ experimentArea.appendChild(ground);
343
+
344
+ // Add ball
345
+ const ball = document.createElement('div');
346
+ ball.id = 'projectileBall';
347
+ ball.className = 'ball bg-red-500 w-8 h-8';
348
+ ball.style.left = '50px';
349
+ ball.style.top = '300px';
350
+ experimentArea.appendChild(ball);
351
+
352
+ // Update initial velocity based on angle
353
+ projectileVelocityX = 5 * Math.cos(angleSlider.value * Math.PI / 180);
354
+ projectileVelocityY = -5 * Math.sin(angleSlider.value * Math.PI / 180);
355
+ }
356
+
357
+ // Setup pendulum experiment
358
+ function setupPendulum() {
359
+ // Add ceiling
360
+ const ceiling = document.createElement('div');
361
+ ceiling.className = 'absolute top-0 left-0 right-0 h-2 bg-blue-800';
362
+ experimentArea.appendChild(ceiling);
363
+
364
+ // Add pivot point
365
+ const pivot = document.createElement('div');
366
+ pivot.className = 'absolute bg-black rounded-full w-5 h-5';
367
+ pivot.style.left = 'calc(50% - 10px)';
368
+ pivot.style.top = '10px';
369
+ experimentArea.appendChild(pivot);
370
+
371
+ // Add string
372
+ const string = document.createElement('div');
373
+ string.id = 'pendulumString';
374
+ string.className = 'pendulum-string w-1 h-60';
375
+ string.style.left = '50%';
376
+ string.style.top = '20px';
377
+ string.style.transformOrigin = 'top center';
378
+ string.style.transform = `rotate(${pendulumAngle}deg)`;
379
+ experimentArea.appendChild(string);
380
+
381
+ // Add bob
382
+ const bob = document.createElement('div');
383
+ bob.id = 'pendulumBob';
384
+ bob.className = 'pendulum-bob w-12 h-12';
385
+ bob.style.left = 'calc(50% - 24px)';
386
+ bob.style.top = '250px';
387
+ experimentArea.appendChild(bob);
388
+ }
389
+
390
+ // Setup spring experiment
391
+ function setupSpring() {
392
+ // Add ceiling
393
+ const ceiling = document.createElement('div');
394
+ ceiling.className = 'absolute top-0 left-0 right-0 h-2 bg-blue-800';
395
+ experimentArea.appendChild(ceiling);
396
+
397
+ // Add spring
398
+ const spring = document.createElement('div');
399
+ spring.id = 'spring';
400
+ spring.className = 'spring w-1 h-40';
401
+ spring.style.left = 'calc(50% - 1px)';
402
+ spring.style.top = '10px';
403
+ experimentArea.appendChild(spring);
404
+
405
+ // Add mass
406
+ const mass = document.createElement('div');
407
+ mass.id = 'springMass';
408
+ mass.className = 'absolute bg-indigo-600 w-16 h-8 rounded-md';
409
+ mass.style.left = 'calc(50% - 32px)';
410
+ mass.style.top = '200px';
411
+ experimentArea.appendChild(mass);
412
+ }
413
+
414
+ // Setup gravity experiment
415
+ function setupGravity() {
416
+ // Add ground
417
+ const ground = document.createElement('div');
418
+ ground.className = 'absolute bottom-0 left-0 right-0 h-2 bg-green-700';
419
+ experimentArea.appendChild(ground);
420
+
421
+ // Add ball
422
+ const ball = document.createElement('div');
423
+ ball.id = 'gravityBall';
424
+ ball.className = 'ball bg-purple-500 w-10 h-10';
425
+ ball.style.left = 'calc(50% - 20px)';
426
+ ball.style.top = '50px';
427
+ experimentArea.appendChild(ball);
428
+ }
429
+
430
+ // Start experiment
431
+ function startExperiment() {
432
+ if (!currentExperiment) return;
433
+
434
+ // Update parameters based on sliders
435
+ const mass = parseFloat(massSlider.value);
436
+ const angle = parseFloat(angleSlider.value);
437
+
438
+ // Reset experiment first
439
+ setupExperiment(currentExperiment);
440
+
441
+ // Start appropriate animation
442
+ switch(currentExperiment) {
443
+ case 'projectile':
444
+ animateProjectile(mass, angle);
445
+ break;
446
+ case 'pendulum':
447
+ animatePendulum(mass);
448
+ break;
449
+ case 'spring':
450
+ animateSpring(mass);
451
+ break;
452
+ case 'gravity':
453
+ animateGravity(mass);
454
+ break;
455
+ }
456
+ }
457
+
458
+ // Animate projectile
459
+ function animateProjectile(mass, angle) {
460
+ const ball = document.getElementById('projectileBall');
461
+ projectileVelocityX = 5 * mass * Math.cos(angle * Math.PI / 180);
462
+ projectileVelocityY = -5 * mass * Math.sin(angle * Math.PI / 180);
463
+
464
+ function update() {
465
+ // Update velocity with gravity
466
+ projectileVelocityY += projectileGravity;
467
+
468
+ // Update position
469
+ projectileX += projectileVelocityX;
470
+ projectileY += projectileVelocityY;
471
+
472
+ // Bounce off bottom
473
+ if (projectileY > experimentArea.offsetHeight - 30) {
474
+ projectileY = experimentArea.offsetHeight - 30;
475
+ projectileVelocityY *= -0.7; // Coefficient of restitution
476
+ projectileVelocityX *= 0.9; // Friction
477
+ }
478
+
479
+ // Update ball position
480
+ ball.style.left = `${projectileX}px`;
481
+ ball.style.top = `${projectileY}px`;
482
+
483
+ // Update stats
484
+ const velocity = Math.sqrt(projectileVelocityX * projectileVelocityX + projectileVelocityY * projectileVelocityY);
485
+ velocityValue.textContent = `${velocity.toFixed(2)} m/s`;
486
+ accelerationValue.textContent = `Y: ${projectileGravity.toFixed(2)} m/s², X: 0 m/s²`;
487
+ forceValue.textContent = `${(mass * projectileGravity).toFixed(2)} N (Weight)`;
488
+
489
+ // Stop if ball stops moving
490
+ if (Math.abs(projectileVelocityX) < 0.1 && Math.abs(projectileVelocityY) < 0.5 && projectileY > experimentArea.offsetHeight - 30) {
491
+ return;
492
+ }
493
+
494
+ animationId = requestAnimationFrame(update);
495
+ }
496
+
497
+ update();
498
+ }
499
+
500
+ // Animate pendulum
501
+ function animatePendulum(mass) {
502
+ const string = document.getElementById('pendulumString');
503
+ const bob = document.getElementById('pendulumBob');
504
+
505
+ const length = 250; // Pendulum length in pixels
506
+ const damping = 0.995; // Damping factor
507
+ const gravity = 0.1 * mass;
508
+
509
+ function update() {
510
+ // Calculate angular acceleration
511
+ const acceleration = -gravity * Math.sin(pendulumAngle * Math.PI / 180);
512
+
513
+ // Update angular velocity
514
+ pendulumDirection += acceleration;
515
+
516
+ // Update angle
517
+ pendulumAngle += pendulumDirection;
518
+
519
+ // Apply damping
520
+ pendulumDirection *= damping;
521
+
522
+ // Update pendulum position
523
+ string.style.transform = `rotate(${pendulumAngle}deg)`;
524
+
525
+ // Calculate bob position
526
+ const bobX = experimentArea.offsetWidth / 2 + length * Math.sin(pendulumAngle * Math.PI / 180);
527
+ const bobY = 20 + length * Math.cos(pendulumAngle * Math.PI / 180);
528
+
529
+ bob.style.left = `${bobX - 24}px`;
530
+ bob.style.top = `${bobY}px`;
531
+
532
+ // Update stats
533
+ const velocity = Math.abs(pendulumDirection * length) / 10;
534
+ velocityValue.textContent = `${velocity.toFixed(2)} m/s`;
535
+
536
+ const angularAcceleration = Math.abs(acceleration);
537
+ accelerationValue.textContent = `${angularAcceleration.toFixed(2)} rad/s²`;
538
+
539
+ const force = mass * gravity * Math.sin(pendulumAngle * Math.PI / 180);
540
+ forceValue.textContent = `${force.toFixed(2)} N (Restoring force)`;
541
+
542
+ animationId = requestAnimationFrame(update);
543
+ }
544
+
545
+ update();
546
+ }
547
+
548
+ // Animate spring
549
+ function animateSpring(mass) {
550
+ const spring = document.getElementById('spring');
551
+ const massElement = document.getElementById('springMass');
552
+
553
+ const springConstant = 0.5; // k in Hooke's Law
554
+ const damping = 0.98; // Damping factor
555
+ let velocity = 0;
556
+
557
+ function update() {
558
+ // Calculate displacement from equilibrium
559
+ const equilibrium = 300 - 30 * mass;
560
+ const displacement = springPosition - equilibrium;
561
+
562
+ // Calculate acceleration (Hooke's Law: F = -kx)
563
+ const acceleration = -springConstant * displacement / mass;
564
+
565
+ // Update velocity
566
+ velocity += acceleration;
567
+ velocity *= damping;
568
+
569
+ // Update position
570
+ springPosition += velocity;
571
+
572
+ // Update spring and mass position
573
+ spring.style.height = `${springPosition}px`;
574
+ massElement.style.top = `${springPosition - 8}px`;
575
+
576
+ // Update stats
577
+ velocityValue.textContent = `${Math.abs(velocity).toFixed(2)} m/s`;
578
+ accelerationValue.textContent = `${Math.abs(acceleration).toFixed(2)} m/s²`;
579
+ forceValue.textContent = `${Math.abs(springConstant * displacement).toFixed(2)} N (Spring force)`;
580
+
581
+ animationId = requestAnimationFrame(update);
582
+ }
583
+
584
+ update();
585
+ }
586
+
587
+ // Animate gravity
588
+ function animateGravity(mass) {
589
+ const ball = document.getElementById('gravityBall');
590
+ let velocity = 0;
591
+
592
+ function update() {
593
+ // Apply gravity
594
+ const gravity = 0.5 * mass;
595
+ velocity += gravity;
596
+
597
+ // Update position
598
+ gravityPosition += velocity;
599
+
600
+ // Stop at ground
601
+ if (gravityPosition > experimentArea.offsetHeight - 30) {
602
+ gravityPosition = experimentArea.offsetHeight - 30;
603
+ velocity *= -0.5; // Bounce with coefficient of restitution
604
+ }
605
+
606
+ // Update ball position
607
+ ball.style.top = `${gravityPosition}px`;
608
+
609
+ // Update stats
610
+ velocityValue.textContent = `${velocity.toFixed(2)} m/s`;
611
+ accelerationValue.textContent = `${gravity.toFixed(2)} m/s²`;
612
+ forceValue.textContent = `${(mass * gravity).toFixed(2)} N (Weight)`;
613
+
614
+ animationId = requestAnimationFrame(update);
615
+ }
616
+
617
+ update();
618
+ }
619
+
620
+ // Reset experiment
621
+ function resetExperiment() {
622
+ if (currentExperiment) {
623
+ setupExperiment(currentExperiment);
624
+ }
625
+
626
+ // Reset stats
627
+ velocityValue.textContent = '0 m/s';
628
+ accelerationValue.textContent = '0 m/s²';
629
+ forceValue.textContent = '0 N';
630
+ }
631
+ </script>
632
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=AARIFSHABIR/virtual-physics" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
633
+ </html>
prompts.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Make virtual physics app prepared by IITians in India