Changed around line 1
+ class Organelle {
+ constructor(type, x, y, size, color) {
+ this.type = type;
+ this.x = x;
+ this.y = y;
+ this.size = size;
+ this.color = color;
+ this.dx = (Math.random() - 0.5) * 2;
+ this.dy = (Math.random() - 0.5) * 2;
+ this.highlighted = false;
+ }
+
+ update(canvas) {
+ this.x += this.dx * speedMultiplier;
+ this.y += this.dy * speedMultiplier;
+
+ if (this.x <= this.size || this.x >= canvas.width - this.size) this.dx *= -1;
+ if (this.y <= this.size || this.y >= canvas.height - this.size) this.dy *= -1;
+ }
+
+ draw(ctx) {
+ ctx.beginPath();
+ ctx.fillStyle = this.highlighted ? '#e74c3c' : this.color;
+ ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
+ ctx.fill();
+ ctx.strokeStyle = 'rgba(0,0,0,0.2)';
+ ctx.stroke();
+ }
+ }
+
+ let canvas, ctx, organelles = [], speedMultiplier = 1;
+ const descriptions = {
+ nucleus: "The nucleus contains genetic material and controls cellular activities.",
+ mitochondria: "Mitochondria are the powerhouse of the cell, generating energy through ATP production.",
+ golgi: "The Golgi apparatus packages and processes proteins for cellular export.",
+ er: "The endoplasmic reticulum synthesizes proteins and lipids."
+ };
+
+ function init() {
+ canvas = document.getElementById('cellCanvas');
+ ctx = canvas.getContext('2d');
+
+ function resizeCanvas() {
+ canvas.width = canvas.offsetWidth;
+ canvas.height = canvas.offsetHeight;
+ }
+
+ resizeCanvas();
+ window.addEventListener('resize', resizeCanvas);
+
+ // Create organelles
+ organelles = [
+ new Organelle('nucleus', canvas.width/2, canvas.height/2, 40, '#2980b9'),
+ ...Array(5).fill().map(() => new Organelle('mitochondria',
+ Math.random() * canvas.width,
+ Math.random() * canvas.height,
+ 15,
+ '#e67e22'
+ )),
+ ...Array(3).fill().map(() => new Organelle('golgi',
+ Math.random() * canvas.width,
+ Math.random() * canvas.height,
+ 20,
+ '#27ae60'
+ )),
+ ...Array(4).fill().map(() => new Organelle('er',
+ Math.random() * canvas.width,
+ Math.random() * canvas.height,
+ 12,
+ '#8e44ad'
+ ))
+ ];
+
+ document.getElementById('speedSlider').addEventListener('input', (e) => {
+ speedMultiplier = e.target.value;
+ });
+
+ document.querySelectorAll('.control-btn').forEach(btn => {
+ btn.addEventListener('click', () => {
+ const organelleType = btn.dataset.organelle;
+ highlightOrganelle(organelleType);
+ });
+ });
+
+ animate();
+ }
+
+ function highlightOrganelle(type) {
+ organelles.forEach(org => {
+ org.highlighted = org.type === type;
+ });
+
+ document.getElementById('organelle-title').textContent =
+ `Current Selection: ${type.charAt(0).toUpperCase() + type.slice(1)}`;
+ document.getElementById('organelle-description').textContent =
+ descriptions[type] || 'Select an organelle to learn more about its function';
+ }
+
+ function animate() {
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+
+ // Draw cell membrane
+ ctx.beginPath();
+ ctx.strokeStyle = '#34495e';
+ ctx.lineWidth = 2;
+ ctx.ellipse(canvas.width/2, canvas.height/2, canvas.width/2.2, canvas.height/2.2, 0, 0, Math.PI * 2);
+ ctx.stroke();
+
+ organelles.forEach(organelle => {
+ organelle.update(canvas);
+ organelle.draw(ctx);
+ });
+
+ requestAnimationFrame(animate);
+ }
+
+ document.addEventListener('DOMContentLoaded', init);