// Cloudflare Worker script class KnowledgeUniverse { constructor() { this.scene = new THREE.Scene(); this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); this.renderer = new THREE.WebGLRenderer({ antialias: true }); this.clock = new THREE.Clock(); this.nodes = []; this.connections = []; } init() { this.setupRenderer(); this.setupCamera(); this.createStars(); this.createNodes(); this.createConnections(); this.setupLighting(); this.addEventListeners(); this.animate(); } setupRenderer() { this.renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(this.renderer.domElement); } setupCamera() { this.camera.position.z = 100; } createStars() { const starsGeometry = new THREE.BufferGeometry(); const starsMaterial = new THREE.PointsMaterial({ color: 0xffffff, size: 0.1, transparent: true, opacity: 0.8, vertexColors: true }); const starsVertices = []; const starsColors = []; for (let i = 0; i < 20000; i++) { starsVertices.push( (Math.random() - 0.5) * 2000, (Math.random() - 0.5) * 2000, (Math.random() - 0.5) * 2000 ); starsColors.push(Math.random(), Math.random(), Math.random()); } starsGeometry.setAttribute('position', new THREE.Float32BufferAttribute(starsVertices, 3)); starsGeometry.setAttribute('color', new THREE.Float32BufferAttribute(starsColors, 3)); const starField = new THREE.Points(starsGeometry, starsMaterial); this.scene.add(starField); } createNodes() { const nodeGeometry = new THREE.SphereGeometry(0.5, 32, 32); const nodeMaterial = new THREE.MeshPhongMaterial({ color: 0x00ffff, emissive: 0x0088ff, specular: 0xffffff, shininess: 100 }); for (let i = 0; i < 100; i++) { const node = new THREE.Mesh(nodeGeometry, nodeMaterial); node.position.set( (Math.random() - 0.5) * 200, (Math.random() - 0.5) * 200, (Math.random() - 0.5) * 200 ); node.scale.setScalar(Math.random() * 2 + 0.5); this.scene.add(node); this.nodes.push(node); } } createConnections() { const lineMaterial = new THREE.LineBasicMaterial({ color: 0x0088ff, transparent: true, opacity: 0.3 }); for (let i = 0; i < this.nodes.length; i++) { for (let j = i + 1; j < this.nodes.length; j++) { if (Math.random() > 0.99) { const geometry = new THREE.BufferGeometry().setFromPoints([ this.nodes[i].position, this.nodes[j].position ]); const line = new THREE.Line(geometry, lineMaterial); this.scene.add(line); this.connections.push(line); } } } } setupLighting() { const ambientLight = new THREE.AmbientLight(0x404040); this.scene.add(ambientLight); const pointLight = new THREE.PointLight(0xffffff, 1, 100); pointLight.position.set(10, 10, 10); this.scene.add(pointLight); } addEventListeners() { window.addEventListener('resize', () => { this.camera.aspect = window.innerWidth / window.innerHeight; this.camera.updateProjectionMatrix(); this.renderer.setSize(window.innerWidth, window.innerHeight); }); } animate() { requestAnimationFrame(this.animate.bind(this)); const elapsedTime = this.clock.getElapsedTime(); // Rotate and pulse nodes this.nodes.forEach((node, index) => { node.rotation.x += 0.01; node.rotation.y += 0.01; node.scale.setScalar(Math.sin(elapsedTime * 2 + index) * 0.1 + 1); }); // Update star colors const starsGeometry = this.scene.children[0].geometry; const colors = starsGeometry.attributes.color.array; for (let i = 0; i < colors.length; i += 3) { colors[i] = Math.sin(elapsedTime + i) * 0.5 + 0.5; colors[i + 1] = Math.sin(elapsedTime + i + 2) * 0.5 + 0.5; colors[i + 2] = Math.sin(elapsedTime + i + 4) * 0.5 + 0.5; } starsGeometry.attributes.color.needsUpdate = true; // Update connections this.connections.forEach((connection, index) => { connection.material.opacity = (Math.sin(elapsedTime * 2 + index) + 1) / 4 + 0.1; }); this.renderer.render(this.scene, this.camera); } } // Initialize the Knowledge Universe const knowledgeUniverse = new KnowledgeUniverse(); knowledgeUniverse.init(); addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)); }); async function handleRequest(request) { // Serve the worker script return new Response( `${KnowledgeUniverse.toString()}\n\nconst knowledgeUniverse = new KnowledgeUniverse();\nknowledgeUniverse.init();`, { headers: { 'content-type': 'application/javascript' }, } ); }