Spaces:
Running
Running
Download galaxie.html from davyes0101/vortex: direct link, hf CLI and curl.
- Browser
- Download file 3.87 kB
-
https://huggingface.co/spaces/davyes0101/vortex/resolve/main/galaxie.html
- Command line
-
hf download hf://spaces/davyes0101/vortex/galaxie.html
-
curl -L -o galaxie.html https://huggingface.co/spaces/davyes0101/vortex/resolve/main/galaxie.html
3.87 kB
| <html lang="fr"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Galaxie en rotation</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script> | |
| <style> | |
| body, html { | |
| margin: 0; | |
| padding: 0; | |
| overflow: hidden; | |
| background-color: #000; | |
| } | |
| canvas { | |
| display: block; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="galaxy-container"></div> | |
| <script> | |
| // Scene setup | |
| const scene = new THREE.Scene(); | |
| const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); | |
| const renderer = new THREE.WebGLRenderer({ antialias: true }); | |
| renderer.setSize(window.innerWidth, window.innerHeight); | |
| document.getElementById('galaxy-container').appendChild(renderer.domElement); | |
| // Galaxy parameters | |
| const galaxyParams = { | |
| stars: 5000, | |
| arms: 4, | |
| armWidth: 0.5, | |
| coreRadius: 2, | |
| armLength: 10, | |
| rotationSpeed: 0.002 | |
| }; | |
| // Create stars | |
| const starsGeometry = new THREE.BufferGeometry(); | |
| const starsMaterial = new THREE.PointsMaterial({ | |
| color: 0xffffff, | |
| size: 0.05, | |
| transparent: true, | |
| opacity: 0.8 | |
| }); | |
| const positions = []; | |
| const colors = []; | |
| for (let i = 0; i < galaxyParams.stars; i++) { | |
| // Spiral arm distribution | |
| const arm = Math.floor(Math.random() * galaxyParams.arms); | |
| const distance = Math.random() * galaxyParams.armLength + galaxyParams.coreRadius; | |
| const angle = (arm / galaxyParams.arms) * Math.PI * 2 + Math.random() * galaxyParams.armWidth; | |
| // Convert polar to cartesian coordinates | |
| const x = Math.cos(angle) * distance; | |
| const z = Math.sin(angle) * distance; | |
| const y = (Math.random() - 0.5) * 0.5; | |
| positions.push(x, y, z); | |
| // Color variation (blue for core, white for arms) | |
| const colorIntensity = 1 - (distance / (galaxyParams.armLength + galaxyParams.coreRadius)); | |
| colors.push( | |
| colorIntensity * 0.5 + 0.5, | |
| colorIntensity * 0.7 + 0.3, | |
| 1.0 | |
| ); | |
| } | |
| starsGeometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3)); | |
| starsGeometry.setAttribute('color', new THREE.Float32BufferAttribute(colors, 3)); | |
| const stars = new THREE.Points(starsGeometry, starsMaterial); | |
| scene.add(stars); | |
| // Core glow | |
| const coreGeometry = new THREE.SphereGeometry(galaxyParams.coreRadius * 0.7, 32, 32); | |
| const coreMaterial = new THREE.MeshBasicMaterial({ | |
| color: 0x4488ff, | |
| transparent: true, | |
| opacity: 0.3 | |
| }); | |
| const core = new THREE.Mesh(coreGeometry, coreMaterial); | |
| scene.add(core); | |
| // Camera position | |
| camera.position.z = 20; | |
| camera.position.y = 7; | |
| // Animation | |
| function animate() { | |
| requestAnimationFrame(animate); | |
| // Rotate galaxy | |
| stars.rotation.y += galaxyParams.rotationSpeed; | |
| renderer.render(scene, camera); | |
| } | |
| // Handle window resize | |
| window.addEventListener('resize', () => { | |
| camera.aspect = window.innerWidth / window.innerHeight; | |
| camera.updateProjectionMatrix(); | |
| renderer.setSize(window.innerWidth, window.innerHeight); | |
| }); | |
| animate(); | |
| </script> | |
| </body> | |
| </html> |