write code
run code
CANVASOR
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Three.js Sphere in Modal</title> <style> /* Basic styles */ body { margin: 0; font-family: Arial, sans-serif; background-color: #222; color: white; } /* Modal styles */ .modal { position: fixed; top: 10%; left: 10%; width: 80%; height: 80%; background-color: rgba(0, 0, 0, 0.9); border-radius: 10px; display: flex; justify-content: center; align-items: center; overflow: hidden; } #threeCanvas { width: 100%; height: 100%; } </style> </head> <body> <!-- Modal --> <div class="modal"> <!-- Three.js Canvas Container --> <div id="threeCanvas"></div> </div> <!-- Include Three.js library --> <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script> <script> // Initialize Three.js in the modal container const canvasContainer = document.getElementById('threeCanvas'); // Create scene, camera, and renderer const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera( 75, canvasContainer.offsetWidth / canvasContainer.offsetHeight, 0.1, 1000 ); const renderer = new THREE.WebGLRenderer(); renderer.setSize(canvasContainer.offsetWidth, canvasContainer.offsetHeight); canvasContainer.appendChild(renderer.domElement); // Add ambient light const ambientLight = new THREE.AmbientLight(0xffffff, 0.5); scene.add(ambientLight); // Add point light const pointLight = new THREE.PointLight(0xffffff, 1); pointLight.position.set(5, 5, 5); scene.add(pointLight); // Create a sphere const geometry = new THREE.SphereGeometry(1, 64, 64); const material = new THREE.MeshStandardMaterial({ color: 0xadd8e6, // Light blue wireframe: true, // Wireframe for clear visualization }); const sphere = new THREE.Mesh(geometry, material); scene.add(sphere); // Position the camera camera.position.z = 5; // Animation loop function animate() { requestAnimationFrame(animate); // Rotate the sphere for better visibility sphere.rotation.x += 0.02; sphere.rotation.y += 0.01; // Render the scene renderer.render(scene, camera); } animate(); // Ensure the renderer resizes properly with the modal window.addEventListener('resize', () => { const width = canvasContainer.offsetWidth; const height = canvasContainer.offsetHeight; renderer.setSize(width, height); camera.aspect = width / height; camera.updateProjectionMatrix(); }); </script> </body> </html>
About THIS CODE (CANVASOR.NET):
81
Copy All Code
Download Code.html