Changed around line 1
+ // Initialize Three.js scene
+ let scene, camera, renderer, brain;
+ let isRotating = false;
+
+ function init() {
+ scene = new THREE.Scene();
+ camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
+
+ renderer = new THREE.WebGLRenderer({
+ canvas: document.getElementById('brain-canvas'),
+ antialias: true
+ });
+ renderer.setSize(window.innerWidth, window.innerHeight);
+ renderer.setPixelRatio(window.devicePixelRatio);
+
+ // Add lights
+ const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
+ scene.add(ambientLight);
+
+ const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
+ directionalLight.position.set(0, 10, 10);
+ scene.add(directionalLight);
+
+ // Create brain geometry
+ const geometry = new THREE.SphereGeometry(5, 32, 32);
+ const material = new THREE.MeshPhongMaterial({
+ color: 0xe0a6a6,
+ shininess: 50,
+ wireframe: false
+ });
+
+ brain = new THREE.Mesh(geometry, material);
+ scene.add(brain);
+
+ camera.position.z = 15;
+
+ // Add brain details (gyri and sulci)
+ addBrainDetails();
+
+ animate();
+ }
+
+ function addBrainDetails() {
+ const detailGeometry = new THREE.TorusKnotGeometry(0.3, 0.1, 64, 8);
+ const detailMaterial = new THREE.MeshPhongMaterial({ color: 0xcc8888 });
+
+ for (let i = 0; i < 50; i++) {
+ const detail = new THREE.Mesh(detailGeometry, detailMaterial);
+ const theta = Math.random() * Math.PI * 2;
+ const phi = Math.random() * Math.PI;
+
+ detail.position.x = 5 * Math.sin(phi) * Math.cos(theta);
+ detail.position.y = 5 * Math.sin(phi) * Math.sin(theta);
+ detail.position.z = 5 * Math.cos(phi);
+
+ detail.rotation.x = Math.random() * Math.PI;
+ detail.rotation.y = Math.random() * Math.PI;
+ detail.scale.set(0.5, 0.5, 0.5);
+
+ brain.add(detail);
+ }
+ }
+
+ function animate() {
+ requestAnimationFrame(animate);
+
+ if (isRotating) {
+ brain.rotation.y += 0.01;
+ }
+
+ renderer.render(scene, camera);
+ }
+
+ // Event Listeners
+ document.getElementById('rotate-left').addEventListener('click', () => {
+ brain.rotation.y -= Math.PI / 4;
+ });
+
+ document.getElementById('rotate-right').addEventListener('click', () => {
+ brain.rotation.y += Math.PI / 4;
+ });
+
+ document.getElementById('zoom-in').addEventListener('click', () => {
+ camera.position.z = Math.max(camera.position.z - 1, 8);
+ });
+
+ document.getElementById('zoom-out').addEventListener('click', () => {
+ camera.position.z = Math.min(camera.position.z + 1, 20);
+ });
+
+ // Handle window resize
+ window.addEventListener('resize', () => {
+ camera.aspect = window.innerWidth / window.innerHeight;
+ camera.updateProjectionMatrix();
+ renderer.setSize(window.innerWidth, window.innerHeight);
+ });
+
+ // Initialize when DOM is loaded
+ document.addEventListener('DOMContentLoaded', init);
+
+ // Add drag functionality
+ let isDragging = false;
+ let previousMousePosition = { x: 0, y: 0 };
+
+ document.getElementById('brain-canvas').addEventListener('mousedown', (e) => {
+ isDragging = true;
+ previousMousePosition = {
+ x: e.clientX,
+ y: e.clientY
+ };
+ });
+
+ document.addEventListener('mousemove', (e) => {
+ if (!isDragging) return;
+
+ const deltaMove = {
+ x: e.clientX - previousMousePosition.x,
+ y: e.clientY - previousMousePosition.y
+ };
+
+ brain.rotation.y += deltaMove.x * 0.005;
+ brain.rotation.x += deltaMove.y * 0.005;
+
+ previousMousePosition = {
+ x: e.clientX,
+ y: e.clientY
+ };
+ });
+
+ document.addEventListener('mouseup', () => {
+ isDragging = false;
+ });