Ex 2: Create HTML, CSS, JS code that make 3d planet earth that i can look around using…
- User
Ex 2: Create HTML, CSS, JS code that make 3d planet earth that i can look around using mouse when I press LMB. You can use libraries to help you with that. Create it in one file. Create code only without additional exlpenations. Don't use external images.
Assistant
<!DOCTYPE html> <html> <head> <title>3D Earth</title> <style> body { margin: 0; overflow: hidden; } </style> </head> <body> <script src="https://threejs.org/build/three.min.js"></script> <script src="https://threejs.org/examples/jsm/controls/OrbitControls.js"></script> <script> const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 100); camera.position.z = 15; const renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(renderer.domElement); function createEarthTexture() { const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); canvas.width = 256; canvas.height = 256; ctx.fillStyle = '#87CEEB'; ctx.fillRect(0, 0, 256, 256); ctx.fillStyle = '#3CB371'; ctx.beginPath(); ctx.arc(128, 128, 100, 0, Math.PI * 2); ctx.fill(); ctx.fillStyle = 'rgba(255,255,255,0.5)'; ctx.beginPath(); ctx.arc(128, 128, 120, 0, Math.PI * 2); ctx.fill(); return canvas; } const texture = new THREE.CanvasTexture(createEarthTexture()); const geometry = new THREE.SphereGeometry(5, 32, 32); const material = new THREE.MeshPhongMaterial({ map: texture }); const earth = new THREE.Mesh(geometry, material); scene.add(earth); const ambientLight = new THREE.AmbientLight(0xffffff, 0.5); scene.add(ambientLight); const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5); directionalLight.position.set(1, 1, 1).normalize(); scene.add(directionalLight); const controls = new THREE.OrbitControls(camera, renderer.domElement); controls.enableDamping = true; function animate() { requestAnimationFrame(animate); controls.update(); renderer.render(scene, camera); } animate(); </script> </body> </html>
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.