| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>3D Particle Galaxy</title> |
| <script src="https://cdn.tailwindcss.com"></script> |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script> |
| <script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.min.js"></script> |
| <style> |
| body { |
| margin: 0; |
| overflow: hidden; |
| background: #000; |
| font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; |
| } |
| canvas { |
| display: block; |
| } |
| .overlay { |
| position: absolute; |
| top: 0; |
| left: 0; |
| width: 100%; |
| height: 100%; |
| pointer-events: none; |
| } |
| .title { |
| position: absolute; |
| top: 20px; |
| left: 0; |
| right: 0; |
| text-align: center; |
| font-size: 2.5rem; |
| font-weight: 700; |
| color: rgba(200, 220, 255, 0.8); |
| text-shadow: 0 0 10px rgba(100, 150, 255, 0.5); |
| letter-spacing: 2px; |
| } |
| .controls { |
| position: absolute; |
| bottom: 20px; |
| left: 0; |
| right: 0; |
| text-align: center; |
| color: rgba(180, 200, 255, 0.7); |
| font-size: 0.9rem; |
| } |
| .loading { |
| position: absolute; |
| top: 50%; |
| left: 50%; |
| transform: translate(-50%, -50%); |
| color: rgba(200, 220, 255, 0.8); |
| font-size: 1.2rem; |
| text-align: center; |
| } |
| .nebula-info { |
| position: absolute; |
| top: 80px; |
| right: 20px; |
| max-width: 300px; |
| background: rgba(10, 15, 30, 0.6); |
| border-radius: 10px; |
| padding: 15px; |
| backdrop-filter: blur(5px); |
| border: 1px solid rgba(100, 150, 255, 0.2); |
| pointer-events: auto; |
| } |
| .nebula-title { |
| font-size: 1.2rem; |
| color: #8bb4ff; |
| margin-bottom: 8px; |
| } |
| .nebula-desc { |
| font-size: 0.9rem; |
| color: #a0c0ff; |
| line-height: 1.4; |
| } |
| .stats { |
| position: absolute; |
| top: 20px; |
| right: 20px; |
| color: rgba(180, 200, 255, 0.7); |
| font-size: 0.8rem; |
| } |
| .toggle-ui { |
| position: absolute; |
| bottom: 20px; |
| right: 20px; |
| background: rgba(10, 15, 30, 0.6); |
| color: #a0c0ff; |
| border: 1px solid rgba(100, 150, 255, 0.2); |
| padding: 8px 15px; |
| border-radius: 5px; |
| cursor: pointer; |
| pointer-events: auto; |
| transition: all 0.3s ease; |
| } |
| .toggle-ui:hover { |
| background: rgba(20, 40, 80, 0.7); |
| } |
| </style> |
| </head> |
| <body class="bg-black"> |
| <div class="overlay"> |
| <div class="title">COSMIC NEBULA EXPLORER</div> |
| <div class="nebula-info"> |
| <div class="nebula-title">Orion Nebula</div> |
| <div class="nebula-desc">A diffuse nebula situated in the Milky Way, being one of the brightest nebulae visible to the naked eye. This stellar nursery is 1,344 light-years away.</div> |
| </div> |
| <div class="stats">Particles: 25,000 | FPS: <span id="fps">60</span></div> |
| <div class="controls">Drag to rotate | Scroll to zoom | Click to create supernova</div> |
| <button class="toggle-ui" onclick="toggleUI()">Toggle UI</button> |
| </div> |
| <div class="loading" id="loading">Initializing cosmic simulation...</div> |
|
|
| <script> |
| |
| let scene, camera, renderer, controls; |
| let particleSystem, nebulaSystem; |
| let stars = []; |
| let clock = new THREE.Clock(); |
| let uiVisible = true; |
| |
| |
| const config = { |
| particleCount: 25000, |
| nebulaCount: 8, |
| galaxySize: 2000, |
| rotationSpeed: 0.1, |
| nebulaColors: [ |
| new THREE.Color(0.4, 0.2, 0.8), |
| new THREE.Color(0.2, 0.5, 0.9), |
| new THREE.Color(0.8, 0.3, 0.4), |
| new THREE.Color(0.3, 0.8, 0.5) |
| ], |
| starColors: [ |
| new THREE.Color(1.0, 0.9, 0.7), |
| new THREE.Color(0.9, 0.9, 1.0), |
| new THREE.Color(1.0, 0.7, 0.7) |
| ] |
| }; |
| |
| |
| function init() { |
| |
| scene = new THREE.Scene(); |
| scene.background = new THREE.Color(0x000010); |
| scene.fog = new THREE.FogExp2(0x000020, 0.0008); |
| |
| |
| camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 3000); |
| camera.position.z = 500; |
| |
| |
| renderer = new THREE.WebGLRenderer({ antialias: true }); |
| renderer.setSize(window.innerWidth, window.innerHeight); |
| renderer.setPixelRatio(window.devicePixelRatio); |
| document.body.appendChild(renderer.domElement); |
| |
| |
| controls = new THREE.OrbitControls(camera, renderer.domElement); |
| controls.enableDamping = true; |
| controls.dampingFactor = 0.05; |
| controls.rotateSpeed = 0.5; |
| controls.zoomSpeed = 1.2; |
| |
| |
| createGalaxy(); |
| |
| |
| const ambientLight = new THREE.AmbientLight(0x222244); |
| scene.add(ambientLight); |
| |
| |
| const starLight = new THREE.DirectionalLight(0xffffff, 0.5); |
| starLight.position.set(1, 1, 1); |
| scene.add(starLight); |
| |
| |
| for (let i = 0; i < config.nebulaCount; i++) { |
| const light = new THREE.PointLight(config.nebulaColors[Math.floor(Math.random() * config.nebulaColors.length)], 0.8, 500); |
| light.position.set( |
| (Math.random() - 0.5) * config.galaxySize, |
| (Math.random() - 0.5) * config.galaxySize * 0.2, |
| (Math.random() - 0.5) * config.galaxySize |
| ); |
| scene.add(light); |
| } |
| |
| |
| window.addEventListener('resize', onWindowResize); |
| |
| |
| renderer.domElement.addEventListener('click', createSupernova); |
| |
| |
| document.getElementById('loading').style.display = 'none'; |
| |
| |
| animate(); |
| } |
| |
| |
| function createGalaxy() { |
| |
| const starGeometry = new THREE.BufferGeometry(); |
| const starPositions = new Float32Array(config.particleCount * 3); |
| const starColors = new Float32Array(config.particleCount * 3); |
| const starSizes = new Float32Array(config.particleCount); |
| |
| |
| const nebulaGeometry = new THREE.BufferGeometry(); |
| const nebulaPositions = new Float32Array(config.nebulaCount * 3); |
| const nebulaColors = new Float32Array(config.nebulaCount * 3); |
| const nebulaSizes = new Float32Array(config.nebulaCount); |
| |
| |
| for (let i = 0; i < config.particleCount; i++) { |
| const i3 = i * 3; |
| |
| |
| const radius = Math.random() * config.galaxySize; |
| const angle = Math.random() * Math.PI * 2; |
| const spiral = Math.random() * 0.4; |
| const height = (Math.random() - 0.5) * config.galaxySize * 0.1; |
| |
| starPositions[i3] = Math.cos(angle + spiral * radius) * radius; |
| starPositions[i3 + 1] = height; |
| starPositions[i3 + 2] = Math.sin(angle + spiral * radius) * radius; |
| |
| |
| const colorIndex = Math.floor(Math.random() * config.starColors.length); |
| const color = config.starColors[colorIndex]; |
| starColors[i3] = color.r; |
| starColors[i3 + 1] = color.g; |
| starColors[i3 + 2] = color.b; |
| |
| |
| starSizes[i] = Math.random() * 2.0 + 0.5; |
| |
| |
| stars.push({ |
| radius: radius, |
| angle: angle, |
| spiral: spiral, |
| height: height, |
| speed: 0.1 + Math.random() * 0.3 |
| }); |
| } |
| |
| |
| for (let i = 0; i < config.nebulaCount; i++) { |
| const i3 = i * 3; |
| |
| |
| const radius = Math.random() * config.galaxySize * 0.7; |
| const angle = Math.random() * Math.PI * 2; |
| const height = (Math.random() - 0.5) * config.galaxySize * 0.05; |
| |
| nebulaPositions[i3] = Math.cos(angle) * radius; |
| nebulaPositions[i3 + 1] = height; |
| nebulaPositions[i3 + 2] = Math.sin(angle) * radius; |
| |
| |
| const color = config.nebulaColors[Math.floor(Math.random() * config.nebulaColors.length)]; |
| nebulaColors[i3] = color.r; |
| nebulaColors[i3 + 1] = color.g; |
| nebulaColors[i3 + 2] = color.b; |
| |
| |
| nebulaSizes[i] = 50 + Math.random() * 100; |
| } |
| |
| |
| starGeometry.setAttribute('position', new THREE.BufferAttribute(starPositions, 3)); |
| starGeometry.setAttribute('color', new THREE.BufferAttribute(starColors, 3)); |
| starGeometry.setAttribute('size', new THREE.BufferAttribute(starSizes, 1)); |
| |
| |
| nebulaGeometry.setAttribute('position', new THREE.BufferAttribute(nebulaPositions, 3)); |
| nebulaGeometry.setAttribute('color', new THREE.BufferAttribute(nebulaColors, 3)); |
| nebulaGeometry.setAttribute('size', new THREE.BufferAttribute(nebulaSizes, 1)); |
| |
| |
| const starMaterial = new THREE.PointsMaterial({ |
| size: 1.5, |
| vertexColors: true, |
| transparent: true, |
| opacity: 0.9, |
| sizeAttenuation: true |
| }); |
| |
| |
| const nebulaMaterial = new THREE.PointsMaterial({ |
| size: 1, |
| vertexColors: true, |
| transparent: true, |
| opacity: 0.3, |
| sizeAttenuation: true, |
| blending: THREE.AdditiveBlending |
| }); |
| |
| |
| particleSystem = new THREE.Points(starGeometry, starMaterial); |
| nebulaSystem = new THREE.Points(nebulaGeometry, nebulaMaterial); |
| |
| |
| scene.add(particleSystem); |
| scene.add(nebulaSystem); |
| } |
| |
| |
| function animate() { |
| requestAnimationFrame(animate); |
| |
| const delta = clock.getDelta(); |
| const elapsedTime = clock.getElapsedTime(); |
| |
| |
| controls.update(); |
| |
| |
| const positions = particleSystem.geometry.attributes.position.array; |
| for (let i = 0; i < config.particleCount; i++) { |
| const i3 = i * 3; |
| const star = stars[i]; |
| |
| |
| star.angle += delta * star.speed * (config.galaxySize / (star.radius + 1)) * 0.1; |
| |
| |
| positions[i3] = Math.cos(star.angle + star.spiral * star.radius) * star.radius; |
| positions[i3 + 2] = Math.sin(star.angle + star.spiral * star.radius) * star.radius; |
| |
| |
| positions[i3 + 1] = star.height + Math.sin(elapsedTime * 0.3 + i) * 5; |
| } |
| |
| |
| particleSystem.geometry.attributes.position.needsUpdate = true; |
| |
| |
| const nebulaPositions = nebulaSystem.geometry.attributes.position.array; |
| for (let i = 0; i < config.nebulaCount; i++) { |
| const i3 = i * 3; |
| |
| |
| nebulaPositions[i3] += Math.sin(elapsedTime * 0.1 + i) * 0.3; |
| nebulaPositions[i3 + 1] += Math.cos(elapsedTime * 0.15 + i) * 0.2; |
| nebulaPositions[i3 + 2] += Math.sin(elapsedTime * 0.12 + i * 2) * 0.4; |
| } |
| nebulaSystem.geometry.attributes.position.needsUpdate = true; |
| |
| |
| particleSystem.rotation.y += delta * config.rotationSpeed * 0.05; |
| nebulaSystem.rotation.y += delta * config.rotationSpeed * 0.03; |
| |
| |
| updateFPS(delta); |
| |
| |
| renderer.render(scene, camera); |
| } |
| |
| |
| function createSupernova(event) { |
| |
| const mouse = new THREE.Vector2(); |
| mouse.x = (event.clientX / window.innerWidth) * 2 - 1; |
| mouse.y = -(event.clientY / window.innerHeight) * 2 + 1; |
| |
| |
| const explosionGeometry = new THREE.BufferGeometry(); |
| const explosionCount = 2000; |
| const positions = new Float32Array(explosionCount * 3); |
| const colors = new Float32Array(explosionCount * 3); |
| const sizes = new Float32Array(explosionCount); |
| |
| |
| const raycaster = new THREE.Raycaster(); |
| raycaster.setFromCamera(mouse, camera); |
| const intersects = raycaster.intersectObject(particleSystem); |
| |
| let explosionPosition; |
| if (intersects.length > 0) { |
| explosionPosition = intersects[0].point; |
| } else { |
| |
| explosionPosition = new THREE.Vector3(); |
| raycaster.ray.at(500, explosionPosition); |
| } |
| |
| |
| const explosionColor = new THREE.Color( |
| 0.9 + Math.random() * 0.1, |
| 0.7 + Math.random() * 0.2, |
| 0.3 + Math.random() * 0.2 |
| ); |
| |
| for (let i = 0; i < explosionCount; i++) { |
| const i3 = i * 3; |
| |
| |
| const angle = Math.random() * Math.PI * 2; |
| const elevation = Math.random() * Math.PI - Math.PI / 2; |
| const distance = Math.random() * 50; |
| |
| positions[i3] = explosionPosition.x + Math.cos(angle) * Math.cos(elevation) * distance; |
| positions[i3 + 1] = explosionPosition.y + Math.sin(elevation) * distance; |
| positions[i3 + 2] = explosionPosition.z + Math.sin(angle) * Math.cos(elevation) * distance; |
| |
| colors[i3] = explosionColor.r; |
| colors[i3 + 1] = explosionColor.g; |
| colors[i3 + 2] = explosionColor.b; |
| |
| sizes[i] = Math.random() * 4 + 1; |
| } |
| |
| explosionGeometry.setAttribute('position', new THREE.BufferAttribute(positions, 3)); |
| explosionGeometry.setAttribute('color', new THREE.BufferAttribute(colors, 3)); |
| explosionGeometry.setAttribute('size', new THREE.BufferAttribute(sizes, 1)); |
| |
| const explosionMaterial = new THREE.PointsMaterial({ |
| size: 2, |
| vertexColors: true, |
| transparent: true, |
| opacity: 0.9, |
| sizeAttenuation: true, |
| blending: THREE.AdditiveBlending |
| }); |
| |
| const explosion = new THREE.Points(explosionGeometry, explosionMaterial); |
| scene.add(explosion); |
| |
| |
| let explosionTime = 0; |
| const explosionDuration = 2.0; |
| |
| function updateExplosion() { |
| explosionTime += 0.016; |
| const progress = explosionTime / explosionDuration; |
| |
| if (progress > 1) { |
| scene.remove(explosion); |
| return; |
| } |
| |
| |
| explosionMaterial.opacity = 1 - progress; |
| |
| |
| const positions = explosion.geometry.attributes.position.array; |
| for (let i = 0; i < explosionCount; i++) { |
| const i3 = i * 3; |
| positions[i3] *= 1.02; |
| positions[i3 + 1] *= 1.02; |
| positions[i3 + 2] *= 1.02; |
| } |
| explosion.geometry.attributes.position.needsUpdate = true; |
| |
| requestAnimationFrame(updateExplosion); |
| } |
| |
| updateExplosion(); |
| } |
| |
| |
| function updateFPS(delta) { |
| const fpsElement = document.getElementById('fps'); |
| if (fpsElement) { |
| const fps = Math.round(1 / delta); |
| fpsElement.textContent = fps; |
| } |
| } |
| |
| |
| function onWindowResize() { |
| camera.aspect = window.innerWidth / window.innerHeight; |
| camera.updateProjectionMatrix(); |
| renderer.setSize(window.innerWidth, window.innerHeight); |
| } |
| |
| |
| function toggleUI() { |
| uiVisible = !uiVisible; |
| const overlay = document.querySelector('.overlay'); |
| overlay.style.opacity = uiVisible ? '1' : '0'; |
| } |
| |
| |
| window.onload = init; |
| </script> |
| <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=erdes/galaxy" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> |
| </html> |