Changed around line 1
+ class Particle {
+ constructor(x, y) {
+ this.x = x;
+ this.y = y;
+ this.vx = (Math.random() - 0.5) * 2;
+ this.vy = (Math.random() - 0.5) * 2;
+ this.radius = Math.random() * 3 + 2;
+ this.color = `hsl(${Math.random() * 60 + 180}, 70%, 50%)`;
+ }
+
+ update(speed) {
+ this.x += this.vx * speed;
+ this.y += this.vy * speed;
+ }
+
+ draw(ctx) {
+ ctx.beginPath();
+ ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
+ ctx.fillStyle = this.color;
+ ctx.fill();
+ ctx.closePath();
+ }
+ }
+
+ class CellSimulator {
+ constructor() {
+ this.canvas = document.getElementById('particleCanvas');
+ this.ctx = this.canvas.getContext('2d');
+ this.particles = [];
+ this.speed = 5;
+ this.resizeCanvas();
+ this.bindEvents();
+ this.createParticles(200);
+ this.animate();
+ }
+
+ resizeCanvas() {
+ this.canvas.width = this.canvas.offsetWidth;
+ this.canvas.height = this.canvas.offsetHeight;
+ }
+
+ bindEvents() {
+ window.addEventListener('resize', () => this.resizeCanvas());
+ document.getElementById('resetBtn').addEventListener('click', () => this.reset());
+ document.getElementById('particleCount').addEventListener('input', (e) => {
+ this.createParticles(parseInt(e.target.value));
+ });
+ document.getElementById('particleSpeed').addEventListener('input', (e) => {
+ this.speed = parseInt(e.target.value);
+ });
+ }
+
+ createParticles(count) {
+ this.particles = [];
+ for (let i = 0; i < count; i++) {
+ const x = Math.random() * this.canvas.width;
+ const y = Math.random() * this.canvas.height;
+ this.particles.push(new Particle(x, y));
+ }
+ }
+
+ reset() {
+ this.createParticles(this.particles.length);
+ }
+
+ animate() {
+ this.ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
+ this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
+
+ this.particles.forEach(particle => {
+ particle.update(this.speed);
+
+ if (particle.x < 0 || particle.x > this.canvas.width) particle.vx *= -1;
+ if (particle.y < 0 || particle.y > this.canvas.height) particle.vy *= -1;
+
+ particle.draw(this.ctx);
+ });
+
+ requestAnimationFrame(() => this.animate());
+ }
+ }
+
+ document.addEventListener('DOMContentLoaded', () => {
+ new CellSimulator();
+ });