Update index.html
Browse files- index.html +206 -253
index.html
CHANGED
|
@@ -1,350 +1,303 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
-
<html
|
| 3 |
<head>
|
| 4 |
-
<meta charset="UTF-8">
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>Relativistic Particle Accelerator</title>
|
| 7 |
<style>
|
| 8 |
-
|
| 9 |
-
margin: 0;
|
| 10 |
-
|
| 11 |
-
box-sizing: border-box;
|
| 12 |
-
}
|
| 13 |
-
|
| 14 |
-
body {
|
| 15 |
-
background: #000;
|
| 16 |
-
color: #00ff00;
|
| 17 |
-
font-family: monospace;
|
| 18 |
overflow: hidden;
|
|
|
|
| 19 |
}
|
| 20 |
-
|
| 21 |
-
canvas {
|
| 22 |
-
position: fixed;
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
.controls {
|
| 26 |
position: fixed;
|
| 27 |
-
top:
|
| 28 |
-
left:
|
| 29 |
-
|
| 30 |
-
padding: 15px;
|
| 31 |
-
border: 1px solid #00ff00;
|
| 32 |
-
z-index: 100;
|
| 33 |
}
|
| 34 |
-
|
| 35 |
-
.data {
|
| 36 |
position: fixed;
|
| 37 |
-
top:
|
| 38 |
-
right:
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
min-width: 200px;
|
| 44 |
}
|
| 45 |
-
|
| 46 |
button {
|
| 47 |
-
background: #
|
| 48 |
-
color: #
|
| 49 |
-
border:
|
| 50 |
-
padding:
|
| 51 |
margin: 5px;
|
| 52 |
cursor: pointer;
|
| 53 |
-
font-
|
| 54 |
-
transition:
|
| 55 |
}
|
| 56 |
-
|
| 57 |
button:hover {
|
| 58 |
-
background: #
|
| 59 |
-
color:
|
| 60 |
}
|
| 61 |
</style>
|
| 62 |
</head>
|
| 63 |
<body>
|
| 64 |
-
<canvas id="mainCanvas"></canvas>
|
| 65 |
-
<canvas id="effectCanvas"></canvas>
|
| 66 |
-
|
| 67 |
<div class="controls">
|
| 68 |
-
<button onclick="
|
| 69 |
<button onclick="toggleAcceleration()">Toggle Acceleration</button>
|
| 70 |
<button onclick="toggleCollisions()">Toggle Collisions</button>
|
| 71 |
-
<button onclick="
|
| 72 |
</div>
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
<div>Energy: <span id="energyLevel">0</span> TeV</div>
|
| 76 |
-
<div>Velocity: <span id="velocityC">0</span>c</div>
|
| 77 |
<div>Particles: <span id="particleCount">0</span></div>
|
| 78 |
<div>Collisions: <span id="collisionCount">0</span></div>
|
| 79 |
-
<div>Time Dilation: <span id="timeDilation">1</span>x</div>
|
| 80 |
</div>
|
| 81 |
-
|
| 82 |
<script>
|
| 83 |
-
const
|
| 84 |
-
const
|
| 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 |
-
this.trail = [];
|
| 121 |
-
this.maxTrailLength = 100;
|
| 122 |
-
this.collided = false;
|
| 123 |
-
this.updatePosition();
|
| 124 |
}
|
| 125 |
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
}
|
| 130 |
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
}
|
|
|
|
| 134 |
|
| 135 |
-
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
}
|
| 138 |
|
| 139 |
-
|
| 140 |
-
if (
|
| 141 |
-
|
| 142 |
-
const acceleration = 0.001 * (1 - this.velocity);
|
| 143 |
-
this.velocity = Math.min(0.9999999999, this.velocity + acceleration);
|
| 144 |
-
|
| 145 |
-
// Energy calculation in TeV
|
| 146 |
-
this.energy = (this.gamma - 1) * 0.511e-3 * 1000;
|
| 147 |
}
|
| 148 |
-
|
| 149 |
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
const angleChange = (this.velocity * 0.1) / this.gamma;
|
| 153 |
-
this.angle += this.clockwise ? angleChange : -angleChange;
|
| 154 |
|
| 155 |
-
this.
|
| 156 |
-
this.y = state.centerY + Math.sin(this.angle) * this.radius;
|
| 157 |
-
|
| 158 |
-
this.trail.push({ x: this.x, y: this.y });
|
| 159 |
if (this.trail.length > this.maxTrailLength) {
|
| 160 |
this.trail.shift();
|
| 161 |
}
|
| 162 |
}
|
| 163 |
|
| 164 |
-
|
| 165 |
-
this.
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
ctx.lineWidth = 2 + (this.velocity * 3);
|
| 178 |
-
|
| 179 |
-
for (let i = 0; i < this.trail.length; i++) {
|
| 180 |
-
if (i === 0) {
|
| 181 |
-
ctx.moveTo(this.trail[i].x, this.trail[i].y);
|
| 182 |
-
} else {
|
| 183 |
-
ctx.lineTo(this.trail[i].x, this.trail[i].y);
|
| 184 |
}
|
|
|
|
| 185 |
}
|
| 186 |
-
ctx.stroke();
|
| 187 |
|
| 188 |
-
// Draw particle
|
| 189 |
-
const particleSize = 3 + (this.velocity * 2);
|
| 190 |
ctx.beginPath();
|
| 191 |
-
ctx.fillStyle =
|
|
|
|
| 192 |
ctx.arc(this.x, this.y, particleSize, 0, Math.PI * 2);
|
| 193 |
ctx.fill();
|
| 194 |
|
| 195 |
-
//
|
| 196 |
ctx.beginPath();
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
for (let i = 0; i < particleCount; i++) {
|
| 208 |
-
const angle = (i / particleCount) * Math.PI * 2 + Math.random() * 0.5;
|
| 209 |
-
const speed = baseSpeed * (0.5 + Math.random());
|
| 210 |
-
const velocity = {
|
| 211 |
-
x: Math.cos(angle) * speed,
|
| 212 |
-
y: Math.sin(angle) * speed
|
| 213 |
-
};
|
| 214 |
-
|
| 215 |
-
state.collisions.push({
|
| 216 |
-
x, y,
|
| 217 |
-
velocity,
|
| 218 |
-
life: 1,
|
| 219 |
-
energy: energy * Math.random(),
|
| 220 |
-
color: `hsl(${30 + Math.random() * 60}, 100%, 50%)`
|
| 221 |
-
});
|
| 222 |
-
}
|
| 223 |
-
}
|
| 224 |
-
|
| 225 |
-
function drawAccelerator() {
|
| 226 |
-
// Draw main ring
|
| 227 |
-
mainCtx.beginPath();
|
| 228 |
-
mainCtx.strokeStyle = '#111';
|
| 229 |
-
mainCtx.lineWidth = 20;
|
| 230 |
-
mainCtx.arc(state.centerX, state.centerY, state.ringRadius, 0, Math.PI * 2);
|
| 231 |
-
mainCtx.stroke();
|
| 232 |
-
|
| 233 |
-
// Draw acceleration segments
|
| 234 |
-
for (let i = 0; i < 16; i++) {
|
| 235 |
-
const angle = (i / 16) * Math.PI * 2;
|
| 236 |
-
const x = state.centerX + Math.cos(angle) * state.ringRadius;
|
| 237 |
-
const y = state.centerY + Math.sin(angle) * state.ringRadius;
|
| 238 |
-
|
| 239 |
-
mainCtx.beginPath();
|
| 240 |
-
mainCtx.strokeStyle = state.acceleratorActive ? '#0f0' : '#030';
|
| 241 |
-
mainCtx.lineWidth = 2;
|
| 242 |
-
mainCtx.arc(x, y, 5, 0, Math.PI * 2);
|
| 243 |
-
mainCtx.stroke();
|
| 244 |
}
|
| 245 |
}
|
| 246 |
|
| 247 |
function checkCollisions() {
|
| 248 |
-
if (!
|
| 249 |
|
| 250 |
-
for (let i = 0; i <
|
| 251 |
-
for (let j = i + 1; j <
|
| 252 |
-
const p1 =
|
| 253 |
-
const p2 =
|
| 254 |
|
| 255 |
-
if (p1.clockwise !== p2.clockwise) {
|
| 256 |
const dx = p1.x - p2.x;
|
| 257 |
const dy = p1.y - p2.y;
|
| 258 |
const distance = Math.sqrt(dx * dx + dy * dy);
|
| 259 |
|
| 260 |
if (distance < 10) {
|
| 261 |
-
|
| 262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
p1.collided = true;
|
| 264 |
p2.collided = true;
|
| 265 |
-
|
|
|
|
| 266 |
}
|
| 267 |
}
|
| 268 |
}
|
| 269 |
}
|
| 270 |
|
| 271 |
-
|
|
|
|
| 272 |
}
|
| 273 |
|
| 274 |
-
function
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
effectCtx.arc(p.x, p.y, 2 + p.energy/10, 0, Math.PI * 2);
|
| 293 |
-
effectCtx.fill();
|
| 294 |
-
});
|
| 295 |
-
}
|
| 296 |
-
|
| 297 |
-
function updateUI() {
|
| 298 |
-
const particle = state.particles[0];
|
| 299 |
-
if (particle) {
|
| 300 |
-
document.getElementById('energyLevel').textContent = particle.energy.toFixed(2);
|
| 301 |
-
document.getElementById('velocityC').textContent = particle.velocity.toFixed(9);
|
| 302 |
-
document.getElementById('timeDilation').textContent = particle.gamma.toFixed(2);
|
| 303 |
}
|
| 304 |
-
document.getElementById('particleCount').textContent = state.particles.length;
|
| 305 |
-
document.getElementById('collisionCount').textContent = state.collisionCount;
|
| 306 |
}
|
| 307 |
|
| 308 |
-
function
|
| 309 |
-
|
| 310 |
-
|
|
|
|
| 311 |
}
|
| 312 |
|
| 313 |
function toggleAcceleration() {
|
| 314 |
-
|
| 315 |
}
|
| 316 |
|
| 317 |
function toggleCollisions() {
|
| 318 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
}
|
| 320 |
|
| 321 |
-
function
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
|
|
|
|
|
|
| 325 |
}
|
| 326 |
|
| 327 |
function animate() {
|
| 328 |
-
// Clear
|
| 329 |
-
|
| 330 |
-
|
| 331 |
|
| 332 |
drawAccelerator();
|
| 333 |
-
|
| 334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
particle.update();
|
| 336 |
-
particle.draw(
|
| 337 |
});
|
| 338 |
|
| 339 |
checkCollisions();
|
| 340 |
-
|
| 341 |
-
drawCollisionEffects();
|
| 342 |
-
updateUI();
|
| 343 |
-
|
| 344 |
requestAnimationFrame(animate);
|
| 345 |
}
|
| 346 |
|
| 347 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
animate();
|
| 349 |
</script>
|
| 350 |
</body>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
<head>
|
|
|
|
|
|
|
|
|
|
| 4 |
<style>
|
| 5 |
+
body {
|
| 6 |
+
margin: 0;
|
| 7 |
+
background: black;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
overflow: hidden;
|
| 9 |
+
font-family: Arial, sans-serif;
|
| 10 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
.controls {
|
| 12 |
position: fixed;
|
| 13 |
+
top: 20px;
|
| 14 |
+
left: 20px;
|
| 15 |
+
z-index: 1;
|
|
|
|
|
|
|
|
|
|
| 16 |
}
|
| 17 |
+
.stats {
|
|
|
|
| 18 |
position: fixed;
|
| 19 |
+
top: 20px;
|
| 20 |
+
right: 20px;
|
| 21 |
+
color: #0f0;
|
| 22 |
+
font-family: monospace;
|
| 23 |
+
font-size: 16px;
|
| 24 |
+
text-align: right;
|
|
|
|
| 25 |
}
|
|
|
|
| 26 |
button {
|
| 27 |
+
background: #333;
|
| 28 |
+
color: #0f0;
|
| 29 |
+
border: 2px solid #0f0;
|
| 30 |
+
padding: 10px 20px;
|
| 31 |
margin: 5px;
|
| 32 |
cursor: pointer;
|
| 33 |
+
font-size: 14px;
|
| 34 |
+
transition: 0.3s;
|
| 35 |
}
|
|
|
|
| 36 |
button:hover {
|
| 37 |
+
background: #0f0;
|
| 38 |
+
color: black;
|
| 39 |
}
|
| 40 |
</style>
|
| 41 |
</head>
|
| 42 |
<body>
|
|
|
|
|
|
|
|
|
|
| 43 |
<div class="controls">
|
| 44 |
+
<button onclick="addParticles()">Add Particles</button>
|
| 45 |
<button onclick="toggleAcceleration()">Toggle Acceleration</button>
|
| 46 |
<button onclick="toggleCollisions()">Toggle Collisions</button>
|
| 47 |
+
<button onclick="resetSimulation()">Reset</button>
|
| 48 |
</div>
|
| 49 |
+
<div class="stats">
|
| 50 |
+
<div>Speed: <span id="speedDisplay">0</span>%</div>
|
|
|
|
|
|
|
| 51 |
<div>Particles: <span id="particleCount">0</span></div>
|
| 52 |
<div>Collisions: <span id="collisionCount">0</span></div>
|
|
|
|
| 53 |
</div>
|
| 54 |
+
<canvas id="canvas"></canvas>
|
| 55 |
<script>
|
| 56 |
+
const canvas = document.getElementById('canvas');
|
| 57 |
+
const ctx = canvas.getContext('2d');
|
| 58 |
+
|
| 59 |
+
canvas.width = window.innerWidth;
|
| 60 |
+
canvas.height = window.innerHeight;
|
| 61 |
+
|
| 62 |
+
const centerX = canvas.width / 2;
|
| 63 |
+
const centerY = canvas.height / 2;
|
| 64 |
+
const radius = Math.min(canvas.width, canvas.height) / 3;
|
| 65 |
+
|
| 66 |
+
let particles = [];
|
| 67 |
+
let explosions = [];
|
| 68 |
+
let isAccelerating = true;
|
| 69 |
+
let collisionsEnabled = true;
|
| 70 |
+
let baseSpeed = 0.01;
|
| 71 |
+
let collisionCount = 0;
|
| 72 |
+
|
| 73 |
+
class Explosion {
|
| 74 |
+
constructor(x, y, energy) {
|
| 75 |
+
this.x = x;
|
| 76 |
+
this.y = y;
|
| 77 |
+
this.particles = [];
|
| 78 |
+
this.life = 1;
|
| 79 |
+
|
| 80 |
+
// Create explosion particles
|
| 81 |
+
const particleCount = Math.floor(energy * 100);
|
| 82 |
+
for(let i = 0; i < particleCount; i++) {
|
| 83 |
+
const angle = Math.random() * Math.PI * 2;
|
| 84 |
+
const speed = Math.random() * energy * 10;
|
| 85 |
+
this.particles.push({
|
| 86 |
+
x: x,
|
| 87 |
+
y: y,
|
| 88 |
+
vx: Math.cos(angle) * speed,
|
| 89 |
+
vy: Math.sin(angle) * speed,
|
| 90 |
+
life: 1
|
| 91 |
+
});
|
| 92 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
}
|
| 94 |
|
| 95 |
+
update() {
|
| 96 |
+
this.particles.forEach(p => {
|
| 97 |
+
p.x += p.vx;
|
| 98 |
+
p.y += p.vy;
|
| 99 |
+
p.life *= 0.95;
|
| 100 |
+
p.vx *= 0.98;
|
| 101 |
+
p.vy *= 0.98;
|
| 102 |
+
});
|
| 103 |
+
this.particles = this.particles.filter(p => p.life > 0.01);
|
| 104 |
+
this.life = this.particles.length > 0 ? 1 : 0;
|
| 105 |
}
|
| 106 |
|
| 107 |
+
draw() {
|
| 108 |
+
this.particles.forEach(p => {
|
| 109 |
+
ctx.beginPath();
|
| 110 |
+
const gradient = ctx.createRadialGradient(p.x, p.y, 0, p.x, p.y, 5);
|
| 111 |
+
gradient.addColorStop(0, `rgba(255, 200, 0, ${p.life})`);
|
| 112 |
+
gradient.addColorStop(1, 'rgba(255, 100, 0, 0)');
|
| 113 |
+
ctx.fillStyle = gradient;
|
| 114 |
+
ctx.arc(p.x, p.y, 5, 0, Math.PI * 2);
|
| 115 |
+
ctx.fill();
|
| 116 |
+
});
|
| 117 |
}
|
| 118 |
+
}
|
| 119 |
|
| 120 |
+
class Particle {
|
| 121 |
+
constructor(clockwise) {
|
| 122 |
+
this.angle = clockwise ? 0 : Math.PI;
|
| 123 |
+
this.clockwise = clockwise;
|
| 124 |
+
this.speed = baseSpeed;
|
| 125 |
+
this.trail = [];
|
| 126 |
+
this.maxTrailLength = 20;
|
| 127 |
+
this.collided = false;
|
| 128 |
}
|
| 129 |
|
| 130 |
+
update() {
|
| 131 |
+
if (isAccelerating && !this.collided) {
|
| 132 |
+
this.speed += 0.0001;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
}
|
| 134 |
+
this.angle += this.clockwise ? this.speed : -this.speed;
|
| 135 |
|
| 136 |
+
this.x = centerX + Math.cos(this.angle) * radius;
|
| 137 |
+
this.y = centerY + Math.sin(this.angle) * radius;
|
|
|
|
|
|
|
| 138 |
|
| 139 |
+
this.trail.push({x: this.x, y: this.y});
|
|
|
|
|
|
|
|
|
|
| 140 |
if (this.trail.length > this.maxTrailLength) {
|
| 141 |
this.trail.shift();
|
| 142 |
}
|
| 143 |
}
|
| 144 |
|
| 145 |
+
draw() {
|
| 146 |
+
if (this.collided) return;
|
| 147 |
+
|
| 148 |
+
// Draw trail
|
| 149 |
+
if (this.trail.length > 1) {
|
| 150 |
+
ctx.beginPath();
|
| 151 |
+
ctx.strokeStyle = this.clockwise ?
|
| 152 |
+
`rgba(255,50,50,${this.speed})` :
|
| 153 |
+
`rgba(50,50,255,${this.speed})`;
|
| 154 |
+
ctx.lineWidth = 2;
|
| 155 |
+
ctx.moveTo(this.trail[0].x, this.trail[0].y);
|
| 156 |
+
for (let pos of this.trail) {
|
| 157 |
+
ctx.lineTo(pos.x, pos.y);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
}
|
| 159 |
+
ctx.stroke();
|
| 160 |
}
|
|
|
|
| 161 |
|
| 162 |
+
// Draw particle
|
|
|
|
| 163 |
ctx.beginPath();
|
| 164 |
+
ctx.fillStyle = this.clockwise ? 'red' : 'blue';
|
| 165 |
+
const particleSize = 3 + (this.speed * 20);
|
| 166 |
ctx.arc(this.x, this.y, particleSize, 0, Math.PI * 2);
|
| 167 |
ctx.fill();
|
| 168 |
|
| 169 |
+
// Draw glow
|
| 170 |
ctx.beginPath();
|
| 171 |
+
const gradient = ctx.createRadialGradient(
|
| 172 |
+
this.x, this.y, particleSize,
|
| 173 |
+
this.x, this.y, particleSize + 5
|
| 174 |
+
);
|
| 175 |
+
gradient.addColorStop(0, this.clockwise ? 'rgba(255,0,0,0.5)' : 'rgba(0,0,255,0.5)');
|
| 176 |
+
gradient.addColorStop(1, 'rgba(0,0,0,0)');
|
| 177 |
+
ctx.fillStyle = gradient;
|
| 178 |
+
ctx.arc(this.x, this.y, particleSize + 5, 0, Math.PI * 2);
|
| 179 |
+
ctx.fill();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
}
|
| 181 |
}
|
| 182 |
|
| 183 |
function checkCollisions() {
|
| 184 |
+
if (!collisionsEnabled) return;
|
| 185 |
|
| 186 |
+
for (let i = 0; i < particles.length; i++) {
|
| 187 |
+
for (let j = i + 1; j < particles.length; j++) {
|
| 188 |
+
const p1 = particles[i];
|
| 189 |
+
const p2 = particles[j];
|
| 190 |
|
| 191 |
+
if (!p1.collided && !p2.collided && p1.clockwise !== p2.clockwise) {
|
| 192 |
const dx = p1.x - p2.x;
|
| 193 |
const dy = p1.y - p2.y;
|
| 194 |
const distance = Math.sqrt(dx * dx + dy * dy);
|
| 195 |
|
| 196 |
if (distance < 10) {
|
| 197 |
+
// Create explosion
|
| 198 |
+
explosions.push(new Explosion(
|
| 199 |
+
(p1.x + p2.x) / 2,
|
| 200 |
+
(p1.y + p2.y) / 2,
|
| 201 |
+
(p1.speed + p2.speed)
|
| 202 |
+
));
|
| 203 |
+
|
| 204 |
p1.collided = true;
|
| 205 |
p2.collided = true;
|
| 206 |
+
collisionCount++;
|
| 207 |
+
document.getElementById('collisionCount').textContent = collisionCount;
|
| 208 |
}
|
| 209 |
}
|
| 210 |
}
|
| 211 |
}
|
| 212 |
|
| 213 |
+
// Remove collided particles
|
| 214 |
+
particles = particles.filter(p => !p.collided);
|
| 215 |
}
|
| 216 |
|
| 217 |
+
function drawAccelerator() {
|
| 218 |
+
// Main ring
|
| 219 |
+
ctx.beginPath();
|
| 220 |
+
ctx.strokeStyle = '#333';
|
| 221 |
+
ctx.lineWidth = 15;
|
| 222 |
+
ctx.arc(centerX, centerY, radius, 0, Math.PI * 2);
|
| 223 |
+
ctx.stroke();
|
| 224 |
+
|
| 225 |
+
// Energy points
|
| 226 |
+
for (let i = 0; i < 8; i++) {
|
| 227 |
+
const angle = (i / 8) * Math.PI * 2;
|
| 228 |
+
const x = centerX + Math.cos(angle) * radius;
|
| 229 |
+
const y = centerY + Math.sin(angle) * radius;
|
| 230 |
+
|
| 231 |
+
ctx.beginPath();
|
| 232 |
+
ctx.fillStyle = isAccelerating ? '#0f0' : '#333';
|
| 233 |
+
ctx.arc(x, y, 4, 0, Math.PI * 2);
|
| 234 |
+
ctx.fill();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
}
|
|
|
|
|
|
|
| 236 |
}
|
| 237 |
|
| 238 |
+
function addParticles() {
|
| 239 |
+
particles.push(new Particle(true));
|
| 240 |
+
particles.push(new Particle(false));
|
| 241 |
+
updateStats();
|
| 242 |
}
|
| 243 |
|
| 244 |
function toggleAcceleration() {
|
| 245 |
+
isAccelerating = !isAccelerating;
|
| 246 |
}
|
| 247 |
|
| 248 |
function toggleCollisions() {
|
| 249 |
+
collisionsEnabled = !collisionsEnabled;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
function resetSimulation() {
|
| 253 |
+
particles = [];
|
| 254 |
+
explosions = [];
|
| 255 |
+
baseSpeed = 0.01;
|
| 256 |
+
collisionCount = 0;
|
| 257 |
+
updateStats();
|
| 258 |
}
|
| 259 |
|
| 260 |
+
function updateStats() {
|
| 261 |
+
const currentSpeed = particles.length > 0 ?
|
| 262 |
+
Math.min(100, particles[0].speed * 1000).toFixed(1) : 0;
|
| 263 |
+
document.getElementById('speedDisplay').textContent = currentSpeed;
|
| 264 |
+
document.getElementById('particleCount').textContent = particles.length;
|
| 265 |
+
document.getElementById('collisionCount').textContent = collisionCount;
|
| 266 |
}
|
| 267 |
|
| 268 |
function animate() {
|
| 269 |
+
// Clear with trail effect
|
| 270 |
+
ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
|
| 271 |
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
| 272 |
|
| 273 |
drawAccelerator();
|
| 274 |
+
|
| 275 |
+
// Update and draw explosions
|
| 276 |
+
explosions.forEach(explosion => explosion.update());
|
| 277 |
+
explosions = explosions.filter(explosion => explosion.life > 0);
|
| 278 |
+
explosions.forEach(explosion => explosion.draw());
|
| 279 |
+
|
| 280 |
+
// Update and draw particles
|
| 281 |
+
particles.forEach(particle => {
|
| 282 |
particle.update();
|
| 283 |
+
particle.draw();
|
| 284 |
});
|
| 285 |
|
| 286 |
checkCollisions();
|
| 287 |
+
updateStats();
|
|
|
|
|
|
|
|
|
|
| 288 |
requestAnimationFrame(animate);
|
| 289 |
}
|
| 290 |
|
| 291 |
+
window.addEventListener('resize', () => {
|
| 292 |
+
canvas.width = window.innerWidth;
|
| 293 |
+
canvas.height = window.innerHeight;
|
| 294 |
+
centerX = canvas.width / 2;
|
| 295 |
+
centerY = canvas.height / 2;
|
| 296 |
+
radius = Math.min(canvas.width, canvas.height) / 3;
|
| 297 |
+
});
|
| 298 |
+
|
| 299 |
+
// Start with initial particles
|
| 300 |
+
addParticles();
|
| 301 |
animate();
|
| 302 |
</script>
|
| 303 |
</body>
|