Changed around line 1
+ class CellSimulation {
+ constructor() {
+ this.canvas = document.getElementById('cell-canvas');
+ this.ctx = this.canvas.getContext('2d');
+ this.organelles = [];
+ this.speed = 1;
+ this.selectedOrganelle = 'all';
+ this.resize();
+ this.initOrganelles();
+ this.bindEvents();
+ this.animate();
+ }
+
+ resize() {
+ this.canvas.width = this.canvas.offsetWidth;
+ this.canvas.height = this.canvas.offsetHeight;
+ }
+
+ initOrganelles() {
+ // Nucleus
+ this.organelles.push({
+ type: 'nucleus',
+ x: this.canvas.width / 2,
+ y: this.canvas.height / 2,
+ radius: 40,
+ color: '#2ecc71',
+ dx: 0,
+ dy: 0
+ });
+
+ // Multiple mitochondria
+ for (let i = 0; i < 5; i++) {
+ this.organelles.push({
+ type: 'mitochondria',
+ x: Math.random() * this.canvas.width,
+ y: Math.random() * this.canvas.height,
+ width: 30,
+ height: 15,
+ color: '#e74c3c',
+ dx: (Math.random() - 0.5) * 2,
+ dy: (Math.random() - 0.5) * 2
+ });
+ }
+
+ // ER and Golgi
+ this.organelles.push({
+ type: 'er',
+ points: this.generateERPoints(),
+ color: '#3498db'
+ });
+
+ this.organelles.push({
+ type: 'golgi',
+ x: this.canvas.width * 0.7,
+ y: this.canvas.height * 0.3,
+ color: '#9b59b6'
+ });
+ }
+
+ generateERPoints() {
+ const points = [];
+ let x = 100;
+ let y = 100;
+ for (let i = 0; i < 10; i++) {
+ points.push({
+ x: x + Math.sin(i) * 50,
+ y: y + Math.cos(i) * 50
+ });
+ x += 20;
+ }
+ return points;
+ }
+
+ bindEvents() {
+ window.addEventListener('resize', () => this.resize());
+ document.getElementById('speed-control').addEventListener('input', (e) => {
+ this.speed = parseFloat(e.target.value);
+ });
+ document.getElementById('organelle-select').addEventListener('change', (e) => {
+ this.selectedOrganelle = e.target.value;
+ });
+ }
+
+ draw() {
+ this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
+
+ this.organelles.forEach(organelle => {
+ if (this.selectedOrganelle === 'all' || this.selectedOrganelle === organelle.type) {
+ this.drawOrganelle(organelle);
+ }
+ });
+ }
+
+ drawOrganelle(organelle) {
+ this.ctx.beginPath();
+ this.ctx.fillStyle = organelle.color;
+
+ switch(organelle.type) {
+ case 'nucleus':
+ this.ctx.arc(organelle.x, organelle.y, organelle.radius, 0, Math.PI * 2);
+ break;
+ case 'mitochondria':
+ this.ctx.ellipse(organelle.x, organelle.y, organelle.width, organelle.height, 0, 0, Math.PI * 2);
+ break;
+ case 'er':
+ this.ctx.moveTo(organelle.points[0].x, organelle.points[0].y);
+ organelle.points.forEach(point => {
+ this.ctx.lineTo(point.x, point.y);
+ });
+ this.ctx.lineWidth = 3;
+ this.ctx.strokeStyle = organelle.color;
+ this.ctx.stroke();
+ return;
+ case 'golgi':
+ this.drawGolgi(organelle);
+ return;
+ }
+ this.ctx.fill();
+ }
+
+ drawGolgi(organelle) {
+ for (let i = 0; i < 5; i++) {
+ this.ctx.beginPath();
+ this.ctx.arc(organelle.x, organelle.y + i * 10, 20 - i * 2, 0, Math.PI);
+ this.ctx.strokeStyle = organelle.color;
+ this.ctx.lineWidth = 2;
+ this.ctx.stroke();
+ }
+ }
+
+ update() {
+ this.organelles.forEach(organelle => {
+ if (organelle.type === 'mitochondria') {
+ organelle.x += organelle.dx * this.speed;
+ organelle.y += organelle.dy * this.speed;
+
+ if (organelle.x < 0 || organelle.x > this.canvas.width) organelle.dx *= -1;
+ if (organelle.y < 0 || organelle.y > this.canvas.height) organelle.dy *= -1;
+ }
+ });
+ }
+
+ animate() {
+ this.update();
+ this.draw();
+ requestAnimationFrame(() => this.animate());
+ }
+ }
+
+ document.addEventListener('DOMContentLoaded', () => {
+ new CellSimulation();
+ });