in a single html file, using three.js via CDN, create a rotating sphere of points that…
- User
in a single html file, using three.js via CDN, create a rotating sphere of points that have sliders for rotation speed, colors, number of points, and any other interesting variables that would make for a good user controllable feature.
Assistant
Rotating Sphere of Points with Interactive Controls
Here's a complete HTML file that creates a rotating sphere of points using Three.js with interactive controls for various parameters:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Interactive 3D Point Sphere</title> <script src="https://cdn.jsdelivr.net/npm/three@0.132.2/build/three.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/three@0.132.2/examples/js/controls/OrbitControls.js"></script> <style> body { margin: 0; overflow: hidden; font-family: Arial, sans-serif; } #container { position: relative; width: 100vw; height: 100vh; } #controls { position: absolute; top: 20px; left: 20px; background: rgba(255, 255, 255, 0.8); padding: 15px; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); max-width: 300px; } .control-group { margin-bottom: 10px; } label { display: block; margin-bottom: 5px; font-weight: bold; } input[type="range"] { width: 100%; } .value-display { font-size: 0.8em; color: #666; text-align: right; } h2 { margin-top: 0; border-bottom: 1px solid #ddd; padding-bottom: 5px; } </style> </head> <body> <div id="container"> <div id="controls"> <h2>Sphere Controls</h2> <div class="control-group"> <label for="pointCount">Point Count: <span id="pointCountValue">1000</span></label> <input type="range" id="pointCount" min="100" max="10000" step="100" value="1000"> </div> <div class="control-group"> <label for="pointSize">Point Size: <span id="pointSizeValue">2</span></label> <input type="range" id="pointSize" min="1" max="10" step="0.1" value="2"> </div> <div class="control-group"> <label for="rotationSpeedX">Rotation Speed X: <span id="rotationSpeedXValue">0.01</span></label> <input type="range" id="rotationSpeedX" min="-0.1" max="0.1" step="0.001" value="0.01"> </div> <div class="control-group"> <label for="rotationSpeedY">Rotation Speed Y: <span id="rotationSpeedYValue">0.02</span></label> <input type="range" id="rotationSpeedY" min="-0.1" max="0.1" step="0.001" value="0.02"> </div> <div class="control-group"> <label for="sphereRadius">Sphere Radius: <span id="sphereRadiusValue">5</span></label> <input type="range" id="sphereRadius" min="1" max="20" step="0.1" value="5"> </div> <div class="control-group"> <label for="colorHue">Color Hue: <span id="colorHueValue">0.6</span></label> <input type="range" id="colorHue" min="0" max="1" step="0.01" value="0.6"> </div> <div class="control-group"> <label for="colorSaturation">Color Saturation: <span id="colorSaturationValue">0.8</span></label> <input type="range" id="colorSaturation" min="0" max="1" step="0.01" value="0.8"> </div> <div class="control-group"> <label for="colorValue">Color Value: <span id="colorValueValue">1.0</span></label> <input type="range" id="colorValue" min="0" max="1" step="0.01" value="1.0"> </div> <div class="control-group"> <label for="noiseAmount">Noise Amount: <span id="noiseAmountValue">0.0</span></label> <input type="range" id="noiseAmount" min="0" max="2" step="0.01" value="0.0"> </div> <div class="control-group"> <label for="animateNoise">Animate Noise</label> <input type="checkbox" id="animateNoise" checked> </div> </div> </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); renderer.setPixelRatio(window.devicePixelRatio); document.getElementById('container').appendChild(renderer.domElement); // Controls const controls = new THREE.OrbitControls(camera, renderer.domElement); camera.position.z = 10; controls.update(); // Variables let pointCount = 1000; let pointSize = 2; let rotationSpeedX = 0.01; let rotationSpeedY = 0.02; let sphereRadius = 5; let colorHue = 0.6; let colorSaturation = 0.8; let colorValue = 1.0; let noiseAmount = 0.0; let animateNoise = true; let noiseTime = 0; // Create points let points; createPoints(); // UI event listeners document.getElementById('pointCount').addEventListener('input', function(e) { pointCount = parseInt(e.target.value); document.getElementById('pointCountValue').textContent = pointCount; createPoints(); }); document.getElementById('pointSize').addEventListener('input', function(e) { pointSize = parseFloat(e.target.value); document.getElementById('pointSizeValue').textContent = pointSize; if (points) points.material.size = pointSize; }); document.getElementById('rotationSpeedX').addEventListener('input', function(e) { rotationSpeedX = parseFloat(e.target.value); document.getElementById('rotationSpeedXValue').textContent = rotationSpeedX; }); document.getElementById('rotationSpeedY').addEventListener('input', function(e) { rotationSpeedY = parseFloat(e.target.value); document.getElementById('rotationSpeedYValue').textContent = rotationSpeedY; }); document.getElementById('sphereRadius').addEventListener('input', function(e) { sphereRadius = parseFloat(e.target.value); document.getElementById('sphereRadiusValue').textContent = sphereRadius; createPoints(); }); document.getElementById('colorHue').addEventListener('input', function(e) { colorHue = parseFloat(e.target.value); document.getElementById('colorHueValue').textContent = colorHue; updateColors(); }); document.getElementById('colorSaturation').addEventListener('input', function(e) { colorSaturation = parseFloat(e.target.value); document.getElementById('colorSaturationValue').textContent = colorSaturation; updateColors(); }); document.getElementById('colorValue').addEventListener('input', function(e) { colorValue = parseFloat(e.target.value); document.getElementById('colorValueValue').textContent = colorValue; updateColors(); }); document.getElementById('noiseAmount').addEventListener('input', function(e) { noiseAmount = parseFloat(e.target.value); document.getElementById('noiseAmountValue').textContent = noiseAmount; createPoints(); }); document.getElementById('animateNoise').addEventListener('change', function(e) { animateNoise = e.target.checked; }); // Window resize window.addEventListener('resize', function() { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth, window.innerHeight); }); // Create points function function createPoints() { if (points) scene.remove(points); const positions = new Float32Array(pointCount * 3); const colors = new Float32Array(pointCount * 3); for (let i = 0; i < pointCount; i++) { // Spherical coordinates const theta = Math.random() * Math.PI * 2; const phi
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.