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 Lighting Example</title> <style> /* Basic styles for the page */ body { margin: 0; font-family: Arial, sans-serif; background-color: #222; color: white; } /* Modal container 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; } /* Canvas container styles */ #threeCanvas { width: 100%; height: 100%; } /* Slider container styles */ .slider-container { position: absolute; bottom: 10px; width: 100%; display: flex; justify-content: center; align-items: center; gap: 20px; } .slider { width: 200px; } label { color: white; } </style> </head> <body> <!-- Modal to contain the Three.js canvas --> <div class="modal"> <!-- Div container for Three.js rendering --> <div id="threeCanvas"></div> </div> <!-- Slider controls for light intensity and direction --> <div class="slider-container"> <div> <label for="intensitySlider">Light Intensity</label> <input type="range" id="intensitySlider" class="slider" min="0" max="2" step="0.01" value="0.8"> </div> <div> <label for="directionSliderX">Light Direction X</label> <input type="range" id="directionSliderX" class="slider" min="-5" max="5" step="0.1" value="5"> </div> <div> <label for="directionSliderY">Light Direction Y</label> <input type="range" id="directionSliderY" class="slider" min="-5" max="5" step="0.1" value="5"> </div> <div> <label for="directionSliderZ">Light Direction Z</label> <input type="range" id="directionSliderZ" class="slider" min="-5" max="5" step="0.1" value="5"> </div> </div> <!-- Include the Three.js library from a CDN --> <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script> <script> // Select the container for rendering the Three.js scene const canvasContainer = document.getElementById('threeCanvas'); // Create the Three.js scene const scene = new THREE.Scene(); // Create a perspective camera const camera = new THREE.PerspectiveCamera( 75, // Field of view in degrees canvasContainer.offsetWidth / canvasContainer.offsetHeight, // Aspect ratio 0.1, // Near clipping plane 1000 // Far clipping plane ); // Create the WebGL renderer const renderer = new THREE.WebGLRenderer(); renderer.setSize(canvasContainer.offsetWidth, canvasContainer.offsetHeight); canvasContainer.appendChild(renderer.domElement); // Add ambient light to the scene const ambientLight = new THREE.AmbientLight(0xffffff, 0.3); scene.add(ambientLight); // Add directional light to the scene const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8); directionalLight.position.set(5, 5, 5); directionalLight.castShadow = true; scene.add(directionalLight); // Create the geometry for a sphere const geometry = new THREE.SphereGeometry(1, 64, 64); // Create the material for the sphere const material = new THREE.MeshStandardMaterial({ color: 0xadd8e6, wireframe: false }); // Create the sphere mesh by combining geometry and material const sphere = new THREE.Mesh(geometry, material); scene.add(sphere); // Position the camera to view the sphere camera.position.z = 5; // Function to animate the scene function animate() { requestAnimationFrame(animate); // Rotate the sphere for dynamic visualization sphere.rotation.x += 0.02; sphere.rotation.y += 0.01; // Render the scene from the camera's perspective renderer.render(scene, camera); } // Start the animation loop animate(); // Adjust the renderer size when the window is resized window.addEventListener('resize', () => { const width = canvasContainer.offsetWidth; const height = canvasContainer.offsetHeight; renderer.setSize(width, height); camera.aspect = width / height; camera.updateProjectionMatrix(); }); // Event listeners for the sliders to control light intensity and direction const intensitySlider = document.getElementById('intensitySlider'); const directionSliderX = document.getElementById('directionSliderX'); const directionSliderY = document.getElementById('directionSliderY'); const directionSliderZ = document.getElementById('directionSliderZ'); // Update light intensity and direction when sliders are moved intensitySlider.addEventListener('input', (event) => { directionalLight.intensity = event.target.value; // Update light intensity }); directionSliderX.addEventListener('input', (event) => { directionalLight.position.x = event.target.value; // Update light direction X }); directionSliderY.addEventListener('input', (event) => { directionalLight.position.y = event.target.value; // Update light direction Y }); directionSliderZ.addEventListener('input', (event) => { directionalLight.position.z = event.target.value; // Update light direction Z }); </script> </body> </html>
About THIS CODE (CANVASOR.NET):
81
Copy All Code
Download Code.html