Changed around line 1
+ const canvas = document.getElementById('cellCanvas');
+ const ctx = canvas.getContext('2d');
+ const playPause = document.getElementById('playPause');
+ const resetButton = document.getElementById('reset');
+ const speedControl = document.getElementById('speed');
+
+ let animationId;
+ let isPlaying = true;
+ let particles = [];
+ const particleCount = 500;
+ const colors = ['#4a90e2', '#50e3c2', '#f5a623', '#ffffff'];
+
+ class Particle {
+ constructor() {
+ this.reset();
+ }
+
+ reset() {
+ this.x = Math.random() * canvas.width;
+ this.y = Math.random() * canvas.height;
+ this.vx = (Math.random() - 0.5) * 2;
+ this.vy = (Math.random() - 0.5) * 2;
+ this.radius = Math.random() * 3 + 1;
+ this.color = colors[Math.floor(Math.random() * colors.length)];
+ this.opacity = Math.random() * 0.5 + 0.5;
+ }
+
+ draw() {
+ ctx.beginPath();
+ ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
+ ctx.fillStyle = this.color;
+ ctx.globalAlpha = this.opacity;
+ ctx.fill();
+ ctx.closePath();
+ }
+
+ update() {
+ this.x += this.vx * speedControl.value;
+ this.y += this.vy * speedControl.value;
+
+ if (this.x < 0 || this.x > canvas.width) this.vx *= -1;
+ if (this.y < 0 || this.y > canvas.height) this.vy *= -1;
+ }
+ }
+
+ function init() {
+ canvas.width = canvas.offsetWidth;
+ canvas.height = canvas.offsetHeight;
+ particles = [];
+ for (let i = 0; i < particleCount; i++) {
+ particles.push(new Particle());
+ }
+ }
+
+ function animate() {
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+ particles.forEach(particle => {
+ particle.update();
+ particle.draw();
+ });
+ if (isPlaying) {
+ animationId = requestAnimationFrame(animate);
+ }
+ }
+
+ function toggleAnimation() {
+ isPlaying = !isPlaying;
+ playPause.textContent = isPlaying ? '❚❚' : '▶';
+ if (isPlaying) {
+ animate();
+ } else {
+ cancelAnimationFrame(animationId);
+ }
+ }
+
+ function resetSimulation() {
+ particles.forEach(particle => particle.reset());
+ }
+
+ window.addEventListener('resize', () => {
+ canvas.width = canvas.offsetWidth;
+ canvas.height = canvas.offsetHeight;
+ });
+
+ playPause.addEventListener('click', toggleAnimation);
+ resetButton.addEventListener('click', resetSimulation);
+
+ init();
+ animate();