Add 3 files
Browse files- README.md +7 -5
- index.html +572 -19
- prompts.txt +0 -0
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 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: simple-physic-simulator
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: blue
|
| 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,572 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Physics Box Animations</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/matter-js/0.18.0/matter.min.js"></script>
|
| 9 |
+
<style>
|
| 10 |
+
.physics-container {
|
| 11 |
+
position: relative;
|
| 12 |
+
overflow: hidden;
|
| 13 |
+
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
.box {
|
| 17 |
+
position: absolute;
|
| 18 |
+
display: flex;
|
| 19 |
+
align-items: center;
|
| 20 |
+
justify-content: center;
|
| 21 |
+
font-weight: bold;
|
| 22 |
+
user-select: none;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
.controls-panel {
|
| 26 |
+
backdrop-filter: blur(10px);
|
| 27 |
+
background-color: rgba(255, 255, 255, 0.8);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.toggle-btn {
|
| 31 |
+
transition: all 0.3s ease;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
.toggle-btn.active {
|
| 35 |
+
background-color: #3b82f6;
|
| 36 |
+
color: white;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
#gravityValue::after {
|
| 40 |
+
content: "↓";
|
| 41 |
+
position: absolute;
|
| 42 |
+
right: -20px;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
#gravityValue.negative::after {
|
| 46 |
+
content: "↑";
|
| 47 |
+
}
|
| 48 |
+
</style>
|
| 49 |
+
</head>
|
| 50 |
+
<body class="bg-gray-100 min-h-screen">
|
| 51 |
+
<div class="container mx-auto px-4 py-8">
|
| 52 |
+
<header class="text-center mb-8">
|
| 53 |
+
<h1 class="text-4xl font-bold text-blue-800 mb-2">Physics Box Playground</h1>
|
| 54 |
+
<p class="text-lg text-gray-600">Interactive demonstrations of physics principles using boxes</p>
|
| 55 |
+
</header>
|
| 56 |
+
|
| 57 |
+
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8">
|
| 58 |
+
<!-- Physics Canvas -->
|
| 59 |
+
<div class="physics-container rounded-xl shadow-xl h-96 w-full" id="physicsCanvas">
|
| 60 |
+
<!-- Boxes will be rendered here by Matter.js -->
|
| 61 |
+
</div>
|
| 62 |
+
|
| 63 |
+
<!-- Controls Panel -->
|
| 64 |
+
<div class="controls-panel rounded-xl shadow-xl p-6 h-96 overflow-y-auto">
|
| 65 |
+
<h2 class="text-2xl font-semibold text-gray-800 mb-4">Simulation Controls</h2>
|
| 66 |
+
|
| 67 |
+
<div class="mb-6">
|
| 68 |
+
<h3 class="text-lg font-medium text-gray-700 mb-2">Simulation Type</h3>
|
| 69 |
+
<div class="flex flex-wrap gap-2 mb-4">
|
| 70 |
+
<button id="freeFallBtn" class="toggle-btn active px-4 py-2 bg-blue-100 text-blue-800 rounded-lg">Free Fall</button>
|
| 71 |
+
<button id="collisionBtn" class="toggle-btn px-4 py-2 bg-blue-100 text-blue-800 rounded-lg">Collisions</button>
|
| 72 |
+
<button id="stackBtn" class="toggle-btn px-4 py-2 bg-blue-100 text-blue-800 rounded-lg">Stacking</button>
|
| 73 |
+
<button id="chainBtn" class="toggle-btn px-4 py-2 bg-blue-100 text-blue-800 rounded-lg">Chain Reaction</button>
|
| 74 |
+
</div>
|
| 75 |
+
</div>
|
| 76 |
+
|
| 77 |
+
<div class="mb-6">
|
| 78 |
+
<h3 class="text-lg font-medium text-gray-700 mb-2">Environment</h3>
|
| 79 |
+
<div class="grid grid-cols-2 gap-4">
|
| 80 |
+
<div>
|
| 81 |
+
<label for="gravitySlider" class="block text-sm font-medium text-gray-700 mb-1">Gravity</label>
|
| 82 |
+
<div class="flex items-center">
|
| 83 |
+
<input type="range" id="gravitySlider" min="-2" max="2" step="0.1" value="1" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer">
|
| 84 |
+
<span id="gravityValue" class="ml-3 w-12 text-center font-medium relative">1.0</span>
|
| 85 |
+
</div>
|
| 86 |
+
</div>
|
| 87 |
+
<div>
|
| 88 |
+
<label for="frictionSlider" class="block text-sm font-medium text-gray-700 mb-1">Friction</label>
|
| 89 |
+
<div class="flex items-center">
|
| 90 |
+
<input type="range" id="frictionSlider" min="0" max="1" step="0.05" value="0.1" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer">
|
| 91 |
+
<span id="frictionValue" class="ml-3 w-12 text-center font-medium">0.1</span>
|
| 92 |
+
</div>
|
| 93 |
+
</div>
|
| 94 |
+
<div>
|
| 95 |
+
<label for="restitutionSlider" class="block text-sm font-medium text-gray-700 mb-1">Bounciness</label>
|
| 96 |
+
<div class="flex items-center">
|
| 97 |
+
<input type="range" id="restitutionSlider" min="0" max="1" step="0.05" value="0.5" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer">
|
| 98 |
+
<span id="restitutionValue" class="ml-3 w-12 text-center font-medium">0.5</span>
|
| 99 |
+
</div>
|
| 100 |
+
</div>
|
| 101 |
+
<div>
|
| 102 |
+
<label for="boxCount" class="block text-sm font-medium text-gray-700 mb-1">Box Count</label>
|
| 103 |
+
<select id="boxCount" class="w-full rounded-lg border-gray-300 text-gray-700">
|
| 104 |
+
<option value="5">5 Boxes</option>
|
| 105 |
+
<option value="10" selected>10 Boxes</option>
|
| 106 |
+
<option value="20">20 Boxes</option>
|
| 107 |
+
<option value="50">50 Boxes</option>
|
| 108 |
+
</select>
|
| 109 |
+
</div>
|
| 110 |
+
</div>
|
| 111 |
+
</div>
|
| 112 |
+
|
| 113 |
+
<div class="flex justify-between">
|
| 114 |
+
<button id="resetBtn" class="px-6 py-2 bg-red-500 text-white rounded-lg hover:bg-red-600 transition">Reset</button>
|
| 115 |
+
<button id="addBoxBtn" class="px-6 py-2 bg-green-500 text-white rounded-lg hover:bg-green-600 transition">Add Box</button>
|
| 116 |
+
</div>
|
| 117 |
+
</div>
|
| 118 |
+
</div>
|
| 119 |
+
|
| 120 |
+
<div class="bg-white rounded-xl shadow-xl p-6 mb-8">
|
| 121 |
+
<h2 class="text-2xl font-semibold text-gray-800 mb-4">Physics Principles Demonstrated</h2>
|
| 122 |
+
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
| 123 |
+
<div class="bg-blue-50 p-4 rounded-lg">
|
| 124 |
+
<h3 class="font-medium text-blue-800 mb-2">Newton's Laws</h3>
|
| 125 |
+
<p class="text-gray-700">Objects in motion stay in motion unless acted upon by an external force. Force equals mass times acceleration.</p>
|
| 126 |
+
</div>
|
| 127 |
+
<div class="bg-purple-50 p-4 rounded-lg">
|
| 128 |
+
<h3 class="font-medium text-purple-800 mb-2">Gravity</h3>
|
| 129 |
+
<p class="text-gray-700">Objects accelerate downward at 9.8 m/s² (adjustable in the simulation).</p>
|
| 130 |
+
</div>
|
| 131 |
+
<div class="bg-green-50 p-4 rounded-lg">
|
| 132 |
+
<h3 class="font-medium text-green-800 mb-2">Collisions</h3>
|
| 133 |
+
<p class="text-gray-700">Momentum is conserved during collisions between objects.</p>
|
| 134 |
+
</div>
|
| 135 |
+
</div>
|
| 136 |
+
</div>
|
| 137 |
+
</div>
|
| 138 |
+
|
| 139 |
+
<script>
|
| 140 |
+
// Matter.js module aliases
|
| 141 |
+
const Engine = Matter.Engine,
|
| 142 |
+
Render = Matter.Render,
|
| 143 |
+
Runner = Matter.Runner,
|
| 144 |
+
Bodies = Matter.Bodies,
|
| 145 |
+
Body = Matter.Body,
|
| 146 |
+
Composite = Matter.Composite,
|
| 147 |
+
Mouse = Matter.Mouse,
|
| 148 |
+
MouseConstraint = Matter.MouseConstraint;
|
| 149 |
+
|
| 150 |
+
// Create engine and renderer
|
| 151 |
+
const engine = Engine.create({
|
| 152 |
+
gravity: { x: 0, y: 1 }
|
| 153 |
+
});
|
| 154 |
+
|
| 155 |
+
const container = document.getElementById('physicsCanvas');
|
| 156 |
+
const render = Render.create({
|
| 157 |
+
element: container,
|
| 158 |
+
engine: engine,
|
| 159 |
+
options: {
|
| 160 |
+
width: container.clientWidth,
|
| 161 |
+
height: container.clientHeight,
|
| 162 |
+
wireframes: false,
|
| 163 |
+
background: 'transparent'
|
| 164 |
+
}
|
| 165 |
+
});
|
| 166 |
+
|
| 167 |
+
// Create runner
|
| 168 |
+
const runner = Runner.create();
|
| 169 |
+
Runner.run(runner, engine);
|
| 170 |
+
Render.run(render);
|
| 171 |
+
|
| 172 |
+
// Add mouse control
|
| 173 |
+
const mouse = Mouse.create(render.canvas);
|
| 174 |
+
const mouseConstraint = MouseConstraint.create(engine, {
|
| 175 |
+
mouse: mouse,
|
| 176 |
+
constraint: {
|
| 177 |
+
stiffness: 0.2,
|
| 178 |
+
render: {
|
| 179 |
+
visible: false
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
});
|
| 183 |
+
Composite.add(engine.world, mouseConstraint);
|
| 184 |
+
render.mouse = mouse;
|
| 185 |
+
|
| 186 |
+
// Keep track of boxes
|
| 187 |
+
let boxes = [];
|
| 188 |
+
let walls = [];
|
| 189 |
+
let currentSimulation = 'freeFall';
|
| 190 |
+
|
| 191 |
+
// Colors for boxes
|
| 192 |
+
const boxColors = [
|
| 193 |
+
'#FF5252', '#FF4081', '#E040FB', '#7C4DFF', '#536DFE',
|
| 194 |
+
'#448AFF', '#40C4FF', '#18FFFF', '#64FFDA', '#69F0AE',
|
| 195 |
+
'#B2FF59', '#EEFF41', '#FFFF00', '#FFD740', '#FFAB40'
|
| 196 |
+
];
|
| 197 |
+
|
| 198 |
+
// Initialize the simulation
|
| 199 |
+
function initSimulation() {
|
| 200 |
+
// Clear existing boxes and walls
|
| 201 |
+
Composite.clear(engine.world);
|
| 202 |
+
boxes = [];
|
| 203 |
+
walls = [];
|
| 204 |
+
|
| 205 |
+
// Add mouse constraint back
|
| 206 |
+
Composite.add(engine.world, mouseConstraint);
|
| 207 |
+
|
| 208 |
+
// Add walls (invisible boundaries)
|
| 209 |
+
const wallOptions = { isStatic: true, render: { visible: false } };
|
| 210 |
+
const wallThickness = 50;
|
| 211 |
+
|
| 212 |
+
walls.push(
|
| 213 |
+
Bodies.rectangle(container.clientWidth / 2, -wallThickness / 2, container.clientWidth, wallThickness, wallOptions), // top
|
| 214 |
+
Bodies.rectangle(container.clientWidth / 2, container.clientHeight + wallThickness / 2, container.clientWidth, wallThickness, wallOptions), // bottom
|
| 215 |
+
Bodies.rectangle(-wallThickness / 2, container.clientHeight / 2, wallThickness, container.clientHeight, wallOptions), // left
|
| 216 |
+
Bodies.rectangle(container.clientWidth + wallThickness / 2, container.clientHeight / 2, wallThickness, container.clientHeight, wallOptions) // right
|
| 217 |
+
);
|
| 218 |
+
|
| 219 |
+
Composite.add(engine.world, walls);
|
| 220 |
+
|
| 221 |
+
// Create boxes based on current simulation type
|
| 222 |
+
const boxCount = parseInt(document.getElementById('boxCount').value);
|
| 223 |
+
|
| 224 |
+
switch(currentSimulation) {
|
| 225 |
+
case 'freeFall':
|
| 226 |
+
createFreeFallBoxes(boxCount);
|
| 227 |
+
break;
|
| 228 |
+
case 'collision':
|
| 229 |
+
createCollisionBoxes(boxCount);
|
| 230 |
+
break;
|
| 231 |
+
case 'stack':
|
| 232 |
+
createStackedBoxes(boxCount);
|
| 233 |
+
break;
|
| 234 |
+
case 'chain':
|
| 235 |
+
createChainReaction(boxCount);
|
| 236 |
+
break;
|
| 237 |
+
}
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
// Create boxes for free fall simulation
|
| 241 |
+
function createFreeFallBoxes(count) {
|
| 242 |
+
for (let i = 0; i < count; i++) {
|
| 243 |
+
const size = Math.random() * 30 + 20;
|
| 244 |
+
const x = Math.random() * (container.clientWidth - size * 2) + size;
|
| 245 |
+
const y = Math.random() * 100;
|
| 246 |
+
const color = boxColors[Math.floor(Math.random() * boxColors.length)];
|
| 247 |
+
|
| 248 |
+
const box = Bodies.rectangle(x, y, size, size, {
|
| 249 |
+
restitution: parseFloat(document.getElementById('restitutionSlider').value),
|
| 250 |
+
friction: parseFloat(document.getElementById('frictionSlider').value),
|
| 251 |
+
render: {
|
| 252 |
+
fillStyle: color,
|
| 253 |
+
strokeStyle: '#000',
|
| 254 |
+
lineWidth: 1
|
| 255 |
+
}
|
| 256 |
+
});
|
| 257 |
+
|
| 258 |
+
boxes.push(box);
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
Composite.add(engine.world, boxes);
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
// Create boxes for collision simulation
|
| 265 |
+
function createCollisionBoxes(count) {
|
| 266 |
+
// Create two groups of boxes that will collide
|
| 267 |
+
const group1Count = Math.floor(count / 2);
|
| 268 |
+
const group2Count = count - group1Count;
|
| 269 |
+
|
| 270 |
+
// Group 1 on the left
|
| 271 |
+
for (let i = 0; i < group1Count; i++) {
|
| 272 |
+
const size = Math.random() * 20 + 20;
|
| 273 |
+
const x = Math.random() * 100 + 50;
|
| 274 |
+
const y = Math.random() * (container.clientHeight - 100) + 50;
|
| 275 |
+
const color = '#448AFF';
|
| 276 |
+
|
| 277 |
+
const box = Bodies.rectangle(x, y, size, size, {
|
| 278 |
+
restitution: parseFloat(document.getElementById('restitutionSlider').value),
|
| 279 |
+
friction: parseFloat(document.getElementById('frictionSlider').value),
|
| 280 |
+
render: {
|
| 281 |
+
fillStyle: color,
|
| 282 |
+
strokeStyle: '#000',
|
| 283 |
+
lineWidth: 1
|
| 284 |
+
}
|
| 285 |
+
});
|
| 286 |
+
|
| 287 |
+
// Give them some initial velocity to the right
|
| 288 |
+
Body.setVelocity(box, { x: 5, y: 0 });
|
| 289 |
+
|
| 290 |
+
boxes.push(box);
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
// Group 2 on the right
|
| 294 |
+
for (let i = 0; i < group2Count; i++) {
|
| 295 |
+
const size = Math.random() * 20 + 20;
|
| 296 |
+
const x = Math.random() * 100 + (container.clientWidth - 200);
|
| 297 |
+
const y = Math.random() * (container.clientHeight - 100) + 50;
|
| 298 |
+
const color = '#FF5252';
|
| 299 |
+
|
| 300 |
+
const box = Bodies.rectangle(x, y, size, size, {
|
| 301 |
+
restitution: parseFloat(document.getElementById('restitutionSlider').value),
|
| 302 |
+
friction: parseFloat(document.getElementById('frictionSlider').value),
|
| 303 |
+
render: {
|
| 304 |
+
fillStyle: color,
|
| 305 |
+
strokeStyle: '#000',
|
| 306 |
+
lineWidth: 1
|
| 307 |
+
}
|
| 308 |
+
});
|
| 309 |
+
|
| 310 |
+
// Give them some initial velocity to the left
|
| 311 |
+
Body.setVelocity(box, { x: -5, y: 0 });
|
| 312 |
+
|
| 313 |
+
boxes.push(box);
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
Composite.add(engine.world, boxes);
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
// Create stacked boxes
|
| 320 |
+
function createStackedBoxes(count) {
|
| 321 |
+
const baseWidth = 200;
|
| 322 |
+
const baseHeight = 30;
|
| 323 |
+
const baseX = container.clientWidth / 2;
|
| 324 |
+
const baseY = container.clientHeight - 50;
|
| 325 |
+
|
| 326 |
+
// Create a base platform
|
| 327 |
+
const base = Bodies.rectangle(baseX, baseY, baseWidth, baseHeight, {
|
| 328 |
+
isStatic: true,
|
| 329 |
+
render: {
|
| 330 |
+
fillStyle: '#795548',
|
| 331 |
+
strokeStyle: '#000',
|
| 332 |
+
lineWidth: 1
|
| 333 |
+
}
|
| 334 |
+
});
|
| 335 |
+
|
| 336 |
+
Composite.add(engine.world, base);
|
| 337 |
+
|
| 338 |
+
// Create stacked boxes
|
| 339 |
+
const maxPerRow = 5;
|
| 340 |
+
const boxSize = 30;
|
| 341 |
+
const rows = Math.ceil(count / maxPerRow);
|
| 342 |
+
|
| 343 |
+
for (let row = 0; row < rows; row++) {
|
| 344 |
+
const boxesInRow = Math.min(count - row * maxPerRow, maxPerRow);
|
| 345 |
+
const rowWidth = boxesInRow * boxSize;
|
| 346 |
+
const startX = baseX - rowWidth / 2 + boxSize / 2;
|
| 347 |
+
|
| 348 |
+
for (let i = 0; i < boxesInRow; i++) {
|
| 349 |
+
const x = startX + i * boxSize;
|
| 350 |
+
const y = baseY - (row + 0.5) * boxSize - 5;
|
| 351 |
+
const color = boxColors[(row * maxPerRow + i) % boxColors.length];
|
| 352 |
+
|
| 353 |
+
const box = Bodies.rectangle(x, y, boxSize - 2, boxSize - 2, {
|
| 354 |
+
restitution: parseFloat(document.getElementById('restitutionSlider').value),
|
| 355 |
+
friction: parseFloat(document.getElementById('frictionSlider').value),
|
| 356 |
+
render: {
|
| 357 |
+
fillStyle: color,
|
| 358 |
+
strokeStyle: '#000',
|
| 359 |
+
lineWidth: 1
|
| 360 |
+
}
|
| 361 |
+
});
|
| 362 |
+
|
| 363 |
+
boxes.push(box);
|
| 364 |
+
}
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
Composite.add(engine.world, boxes);
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
// Create chain reaction
|
| 371 |
+
function createChainReaction(count) {
|
| 372 |
+
// Create a floor for the dominos to stand on
|
| 373 |
+
const floor = Bodies.rectangle(
|
| 374 |
+
container.clientWidth / 2,
|
| 375 |
+
container.clientHeight - 10,
|
| 376 |
+
container.clientWidth,
|
| 377 |
+
20,
|
| 378 |
+
{
|
| 379 |
+
isStatic: true,
|
| 380 |
+
render: {
|
| 381 |
+
fillStyle: '#795548',
|
| 382 |
+
strokeStyle: '#000',
|
| 383 |
+
lineWidth: 1
|
| 384 |
+
}
|
| 385 |
+
}
|
| 386 |
+
);
|
| 387 |
+
|
| 388 |
+
Composite.add(engine.world, floor);
|
| 389 |
+
|
| 390 |
+
// Create dominos
|
| 391 |
+
const dominoWidth = 15;
|
| 392 |
+
const dominoHeight = 60;
|
| 393 |
+
const spacing = 20;
|
| 394 |
+
const startX = 100;
|
| 395 |
+
const startY = container.clientHeight - 20 - dominoHeight/2;
|
| 396 |
+
|
| 397 |
+
// Create a starting ball with more mass
|
| 398 |
+
const ball = Bodies.circle(50, startY - 30, 15, {
|
| 399 |
+
restitution: 0.9,
|
| 400 |
+
density: 0.005, // Higher density for more impact
|
| 401 |
+
render: {
|
| 402 |
+
fillStyle: '#FF5252',
|
| 403 |
+
strokeStyle: '#000',
|
| 404 |
+
lineWidth: 1
|
| 405 |
+
}
|
| 406 |
+
});
|
| 407 |
+
|
| 408 |
+
// Give it a push to the right
|
| 409 |
+
Body.setVelocity(ball, { x: 15, y: 0 });
|
| 410 |
+
|
| 411 |
+
boxes.push(ball);
|
| 412 |
+
|
| 413 |
+
// Create dominos as dynamic bodies (not static)
|
| 414 |
+
for (let i = 0; i < count; i++) {
|
| 415 |
+
const x = startX + i * (dominoWidth + spacing);
|
| 416 |
+
const color = boxColors[i % boxColors.length];
|
| 417 |
+
|
| 418 |
+
const domino = Bodies.rectangle(x, startY, dominoWidth, dominoHeight, {
|
| 419 |
+
chamfer: { radius: 2 },
|
| 420 |
+
friction: 0.3,
|
| 421 |
+
restitution: 0.2,
|
| 422 |
+
render: {
|
| 423 |
+
fillStyle: color,
|
| 424 |
+
strokeStyle: '#000',
|
| 425 |
+
lineWidth: 1
|
| 426 |
+
}
|
| 427 |
+
});
|
| 428 |
+
|
| 429 |
+
// Slightly tilt the dominos forward
|
| 430 |
+
Body.setAngle(domino, -0.1);
|
| 431 |
+
|
| 432 |
+
boxes.push(domino);
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
Composite.add(engine.world, boxes);
|
| 436 |
+
|
| 437 |
+
// Add a wall at the end to stop the last domino
|
| 438 |
+
const endWall = Bodies.rectangle(
|
| 439 |
+
startX + count * (dominoWidth + spacing) + 50,
|
| 440 |
+
container.clientHeight / 2,
|
| 441 |
+
20,
|
| 442 |
+
container.clientHeight,
|
| 443 |
+
{
|
| 444 |
+
isStatic: true,
|
| 445 |
+
render: {
|
| 446 |
+
visible: false
|
| 447 |
+
}
|
| 448 |
+
}
|
| 449 |
+
);
|
| 450 |
+
|
| 451 |
+
Composite.add(engine.world, endWall);
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
// Add a single box
|
| 455 |
+
function addBox() {
|
| 456 |
+
const size = Math.random() * 30 + 20;
|
| 457 |
+
const x = Math.random() * (container.clientWidth - size * 2) + size;
|
| 458 |
+
const y = -50;
|
| 459 |
+
const color = boxColors[Math.floor(Math.random() * boxColors.length)];
|
| 460 |
+
|
| 461 |
+
const box = Bodies.rectangle(x, y, size, size, {
|
| 462 |
+
restitution: parseFloat(document.getElementById('restitutionSlider').value),
|
| 463 |
+
friction: parseFloat(document.getElementById('frictionSlider').value),
|
| 464 |
+
render: {
|
| 465 |
+
fillStyle: color,
|
| 466 |
+
strokeStyle: '#000',
|
| 467 |
+
lineWidth: 1
|
| 468 |
+
}
|
| 469 |
+
});
|
| 470 |
+
|
| 471 |
+
boxes.push(box);
|
| 472 |
+
Composite.add(engine.world, box);
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
// Event listeners for controls
|
| 476 |
+
document.getElementById('freeFallBtn').addEventListener('click', function() {
|
| 477 |
+
currentSimulation = 'freeFall';
|
| 478 |
+
updateActiveButton(this);
|
| 479 |
+
initSimulation();
|
| 480 |
+
});
|
| 481 |
+
|
| 482 |
+
document.getElementById('collisionBtn').addEventListener('click', function() {
|
| 483 |
+
currentSimulation = 'collision';
|
| 484 |
+
updateActiveButton(this);
|
| 485 |
+
initSimulation();
|
| 486 |
+
});
|
| 487 |
+
|
| 488 |
+
document.getElementById('stackBtn').addEventListener('click', function() {
|
| 489 |
+
currentSimulation = 'stack';
|
| 490 |
+
updateActiveButton(this);
|
| 491 |
+
initSimulation();
|
| 492 |
+
});
|
| 493 |
+
|
| 494 |
+
document.getElementById('chainBtn').addEventListener('click', function() {
|
| 495 |
+
currentSimulation = 'chain';
|
| 496 |
+
updateActiveButton(this);
|
| 497 |
+
initSimulation();
|
| 498 |
+
});
|
| 499 |
+
|
| 500 |
+
document.getElementById('gravitySlider').addEventListener('input', function() {
|
| 501 |
+
const value = parseFloat(this.value);
|
| 502 |
+
engine.gravity.y = value;
|
| 503 |
+
document.getElementById('gravityValue').textContent = value.toFixed(1);
|
| 504 |
+
|
| 505 |
+
if (value < 0) {
|
| 506 |
+
document.getElementById('gravityValue').classList.add('negative');
|
| 507 |
+
} else {
|
| 508 |
+
document.getElementById('gravityValue').classList.remove('negative');
|
| 509 |
+
}
|
| 510 |
+
});
|
| 511 |
+
|
| 512 |
+
document.getElementById('frictionSlider').addEventListener('input', function() {
|
| 513 |
+
const value = parseFloat(this.value);
|
| 514 |
+
document.getElementById('frictionValue').textContent = value.toFixed(2);
|
| 515 |
+
|
| 516 |
+
// Update friction for all boxes
|
| 517 |
+
boxes.forEach(box => {
|
| 518 |
+
box.friction = value;
|
| 519 |
+
box.frictionStatic = value * 1.5;
|
| 520 |
+
});
|
| 521 |
+
});
|
| 522 |
+
|
| 523 |
+
document.getElementById('restitutionSlider').addEventListener('input', function() {
|
| 524 |
+
const value = parseFloat(this.value);
|
| 525 |
+
document.getElementById('restitutionValue').textContent = value.toFixed(2);
|
| 526 |
+
|
| 527 |
+
// Update restitution for all boxes
|
| 528 |
+
boxes.forEach(box => {
|
| 529 |
+
box.restitution = value;
|
| 530 |
+
});
|
| 531 |
+
});
|
| 532 |
+
|
| 533 |
+
document.getElementById('boxCount').addEventListener('change', function() {
|
| 534 |
+
initSimulation();
|
| 535 |
+
});
|
| 536 |
+
|
| 537 |
+
document.getElementById('resetBtn').addEventListener('click', function() {
|
| 538 |
+
initSimulation();
|
| 539 |
+
});
|
| 540 |
+
|
| 541 |
+
document.getElementById('addBoxBtn').addEventListener('click', function() {
|
| 542 |
+
addBox();
|
| 543 |
+
});
|
| 544 |
+
|
| 545 |
+
// Helper function to update active button
|
| 546 |
+
function updateActiveButton(activeBtn) {
|
| 547 |
+
document.querySelectorAll('.toggle-btn').forEach(btn => {
|
| 548 |
+
btn.classList.remove('active');
|
| 549 |
+
});
|
| 550 |
+
activeBtn.classList.add('active');
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
// Handle window resize
|
| 554 |
+
window.addEventListener('resize', function() {
|
| 555 |
+
render.options.width = container.clientWidth;
|
| 556 |
+
render.options.height = container.clientHeight;
|
| 557 |
+
Render.setPixelRatio(render, window.devicePixelRatio);
|
| 558 |
+
|
| 559 |
+
// Update wall positions
|
| 560 |
+
if (walls.length >= 4) {
|
| 561 |
+
Body.setPosition(walls[0], { x: container.clientWidth / 2, y: -25 }); // top
|
| 562 |
+
Body.setPosition(walls[1], { x: container.clientWidth / 2, y: container.clientHeight + 25 }); // bottom
|
| 563 |
+
Body.setPosition(walls[2], { x: -25, y: container.clientHeight / 2 }); // left
|
| 564 |
+
Body.setPosition(walls[3], { x: container.clientWidth + 25, y: container.clientHeight / 2 }); // right
|
| 565 |
+
}
|
| 566 |
+
});
|
| 567 |
+
|
| 568 |
+
// Initialize the first simulation
|
| 569 |
+
initSimulation();
|
| 570 |
+
</script>
|
| 571 |
+
<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=leos123122/simple-physic-simulator" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 572 |
+
</html>
|
prompts.txt
ADDED
|
File without changes
|