File size: 10,359 Bytes
fbd9df9
97a124f
fbd9df9
 
97a124f
 
 
fbd9df9
97a124f
fbd9df9
 
 
97a124f
 
 
fbd9df9
97a124f
fbd9df9
97a124f
 
 
 
 
 
fbd9df9
 
97a124f
 
 
 
fbd9df9
 
97a124f
 
fbd9df9
 
97a124f
 
fbd9df9
 
 
 
 
97a124f
fbd9df9
 
97a124f
fbd9df9
97a124f
 
1a8e9f2
 
fbd9df9
97a124f
fbd9df9
97a124f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a8e9f2
 
97a124f
 
 
 
 
 
 
 
 
 
1a8e9f2
 
97a124f
 
 
 
 
 
 
 
 
 
1a8e9f2
97a124f
1a8e9f2
97a124f
 
 
 
 
 
 
 
1a8e9f2
 
97a124f
 
 
1a8e9f2
97a124f
fbd9df9
97a124f
 
1a8e9f2
97a124f
fbd9df9
 
 
 
 
97a124f
 
 
 
 
 
 
 
 
 
 
 
 
fbd9df9
97a124f
fbd9df9
 
97a124f
fbd9df9
97a124f
 
1a8e9f2
fbd9df9
 
97a124f
fbd9df9
97a124f
 
 
 
 
 
 
 
 
fbd9df9
 
 
 
97a124f
fbd9df9
97a124f
 
 
 
fbd9df9
97a124f
fbd9df9
 
 
 
1a8e9f2
97a124f
 
 
 
 
 
 
fbd9df9
 
97a124f
 
fbd9df9
 
 
 
 
97a124f
 
fbd9df9
 
97a124f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a8e9f2
fbd9df9
 
97a124f
 
 
 
fbd9df9
 
 
97a124f
fbd9df9
 
 
97a124f
 
 
 
 
 
 
 
 
fbd9df9
 
97a124f
 
 
 
 
 
1a8e9f2
fbd9df9
1a8e9f2
97a124f
 
 
fbd9df9
 
97a124f
 
 
 
 
 
 
 
fbd9df9
97a124f
fbd9df9
 
 
97a124f
fbd9df9
 
 
97a124f
 
 
 
 
 
 
 
 
 
fbd9df9
 
 
 
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
<!DOCTYPE html>
<html>
<head>
    <style>
        body { 
            margin: 0; 
            background: black; 
            overflow: hidden;
            font-family: Arial, sans-serif;
        }
        .controls {
            position: fixed;
            top: 20px;
            left: 20px;
            z-index: 1;
        }
        .stats {
            position: fixed;
            top: 20px;
            right: 20px;
            color: #0f0;
            font-family: monospace;
            font-size: 16px;
            text-align: right;
        }
        button {
            background: #333;
            color: #0f0;
            border: 2px solid #0f0;
            padding: 10px 20px;
            margin: 5px;
            cursor: pointer;
            font-size: 14px;
            transition: 0.3s;
        }
        button:hover {
            background: #0f0;
            color: black;
        }
    </style>
</head>
<body>
    <div class="controls">
        <button onclick="addParticles()">Add Particles</button>
        <button onclick="toggleAcceleration()">Toggle Acceleration</button>
        <button onclick="toggleCollisions()">Toggle Collisions</button>
        <button onclick="resetSimulation()">Reset</button>
    </div>
    <div class="stats">
        <div>Speed: <span id="speedDisplay">0</span>%</div>
        <div>Particles: <span id="particleCount">0</span></div>
        <div>Collisions: <span id="collisionCount">0</span></div>
    </div>
    <canvas id="canvas"></canvas>
    <script>
        const canvas = document.getElementById('canvas');
        const ctx = canvas.getContext('2d');

        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;

        const centerX = canvas.width / 2;
        const centerY = canvas.height / 2;
        const radius = Math.min(canvas.width, canvas.height) / 3;

        let particles = [];
        let explosions = [];
        let isAccelerating = true;
        let collisionsEnabled = true;
        let baseSpeed = 0.01;
        let collisionCount = 0;

        class Explosion {
            constructor(x, y, energy) {
                this.x = x;
                this.y = y;
                this.particles = [];
                this.life = 1;
                
                // Create explosion particles
                const particleCount = Math.floor(energy * 100);
                for(let i = 0; i < particleCount; i++) {
                    const angle = Math.random() * Math.PI * 2;
                    const speed = Math.random() * energy * 10;
                    this.particles.push({
                        x: x,
                        y: y,
                        vx: Math.cos(angle) * speed,
                        vy: Math.sin(angle) * speed,
                        life: 1
                    });
                }
            }

            update() {
                this.particles.forEach(p => {
                    p.x += p.vx;
                    p.y += p.vy;
                    p.life *= 0.95;
                    p.vx *= 0.98;
                    p.vy *= 0.98;
                });
                this.particles = this.particles.filter(p => p.life > 0.01);
                this.life = this.particles.length > 0 ? 1 : 0;
            }

            draw() {
                this.particles.forEach(p => {
                    ctx.beginPath();
                    const gradient = ctx.createRadialGradient(p.x, p.y, 0, p.x, p.y, 5);
                    gradient.addColorStop(0, `rgba(255, 200, 0, ${p.life})`);
                    gradient.addColorStop(1, 'rgba(255, 100, 0, 0)');
                    ctx.fillStyle = gradient;
                    ctx.arc(p.x, p.y, 5, 0, Math.PI * 2);
                    ctx.fill();
                });
            }
        }

        class Particle {
            constructor(clockwise) {
                this.angle = clockwise ? 0 : Math.PI;
                this.clockwise = clockwise;
                this.speed = baseSpeed;
                this.trail = [];
                this.maxTrailLength = 20;
                this.collided = false;
            }

            update() {
                if (isAccelerating && !this.collided) {
                    this.speed += 0.0001;
                }
                this.angle += this.clockwise ? this.speed : -this.speed;

                this.x = centerX + Math.cos(this.angle) * radius;
                this.y = centerY + Math.sin(this.angle) * radius;

                this.trail.push({x: this.x, y: this.y});
                if (this.trail.length > this.maxTrailLength) {
                    this.trail.shift();
                }
            }

            draw() {
                if (this.collided) return;

                // Draw trail
                if (this.trail.length > 1) {
                    ctx.beginPath();
                    ctx.strokeStyle = this.clockwise ? 
                        `rgba(255,50,50,${this.speed})` : 
                        `rgba(50,50,255,${this.speed})`;
                    ctx.lineWidth = 2;
                    ctx.moveTo(this.trail[0].x, this.trail[0].y);
                    for (let pos of this.trail) {
                        ctx.lineTo(pos.x, pos.y);
                    }
                    ctx.stroke();
                }

                // Draw particle
                ctx.beginPath();
                ctx.fillStyle = this.clockwise ? 'red' : 'blue';
                const particleSize = 3 + (this.speed * 20);
                ctx.arc(this.x, this.y, particleSize, 0, Math.PI * 2);
                ctx.fill();

                // Draw glow
                ctx.beginPath();
                const gradient = ctx.createRadialGradient(
                    this.x, this.y, particleSize,
                    this.x, this.y, particleSize + 5
                );
                gradient.addColorStop(0, this.clockwise ? 'rgba(255,0,0,0.5)' : 'rgba(0,0,255,0.5)');
                gradient.addColorStop(1, 'rgba(0,0,0,0)');
                ctx.fillStyle = gradient;
                ctx.arc(this.x, this.y, particleSize + 5, 0, Math.PI * 2);
                ctx.fill();
            }
        }

        function checkCollisions() {
            if (!collisionsEnabled) return;

            for (let i = 0; i < particles.length; i++) {
                for (let j = i + 1; j < particles.length; j++) {
                    const p1 = particles[i];
                    const p2 = particles[j];

                    if (!p1.collided && !p2.collided && p1.clockwise !== p2.clockwise) {
                        const dx = p1.x - p2.x;
                        const dy = p1.y - p2.y;
                        const distance = Math.sqrt(dx * dx + dy * dy);

                        if (distance < 10) {
                            // Create explosion
                            explosions.push(new Explosion(
                                (p1.x + p2.x) / 2,
                                (p1.y + p2.y) / 2,
                                (p1.speed + p2.speed)
                            ));
                            
                            p1.collided = true;
                            p2.collided = true;
                            collisionCount++;
                            document.getElementById('collisionCount').textContent = collisionCount;
                        }
                    }
                }
            }

            // Remove collided particles
            particles = particles.filter(p => !p.collided);
        }

        function drawAccelerator() {
            // Main ring
            ctx.beginPath();
            ctx.strokeStyle = '#333';
            ctx.lineWidth = 15;
            ctx.arc(centerX, centerY, radius, 0, Math.PI * 2);
            ctx.stroke();

            // Energy points
            for (let i = 0; i < 8; i++) {
                const angle = (i / 8) * Math.PI * 2;
                const x = centerX + Math.cos(angle) * radius;
                const y = centerY + Math.sin(angle) * radius;
                
                ctx.beginPath();
                ctx.fillStyle = isAccelerating ? '#0f0' : '#333';
                ctx.arc(x, y, 4, 0, Math.PI * 2);
                ctx.fill();
            }
        }

        function addParticles() {
            particles.push(new Particle(true));
            particles.push(new Particle(false));
            updateStats();
        }

        function toggleAcceleration() {
            isAccelerating = !isAccelerating;
        }

        function toggleCollisions() {
            collisionsEnabled = !collisionsEnabled;
        }

        function resetSimulation() {
            particles = [];
            explosions = [];
            baseSpeed = 0.01;
            collisionCount = 0;
            updateStats();
        }

        function updateStats() {
            const currentSpeed = particles.length > 0 ? 
                Math.min(100, particles[0].speed * 1000).toFixed(1) : 0;
            document.getElementById('speedDisplay').textContent = currentSpeed;
            document.getElementById('particleCount').textContent = particles.length;
            document.getElementById('collisionCount').textContent = collisionCount;
        }

        function animate() {
            // Clear with trail effect
            ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
            ctx.fillRect(0, 0, canvas.width, canvas.height);

            drawAccelerator();

            // Update and draw explosions
            explosions.forEach(explosion => explosion.update());
            explosions = explosions.filter(explosion => explosion.life > 0);
            explosions.forEach(explosion => explosion.draw());

            // Update and draw particles
            particles.forEach(particle => {
                particle.update();
                particle.draw();
            });

            checkCollisions();
            updateStats();
            requestAnimationFrame(animate);
        }

        window.addEventListener('resize', () => {
            canvas.width = window.innerWidth;
            canvas.height = window.innerHeight;
            centerX = canvas.width / 2;
            centerY = canvas.height / 2;
            radius = Math.min(canvas.width, canvas.height) / 3;
        });

        // Start with initial particles
        addParticles();
        animate();
    </script>
</body>
</html>