Skip to content
The Chat Archive
llama-3.3-70b-instruct· Meta LMArena Human Preference 140K

in a single html file, using three.js via CDN, create a rotating sphere of points that…

  1. 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.

  2. Assistant

    Below is an example of an HTML file that uses Three.js via CDN to create a rotating sphere of points with sliders for rotation speed, colors, number of points, and other interesting variables.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Rotating Sphere of Points</title>
        <style>
            body {
                margin: 0;
                background-color: #f0f0f0;
                font-family: Monospace;
                font-size: 13px;
                line-height: 24px;
                overscroll-behavior: none;
                text-rendering: optimizeLegibility;
                user-select: none;
                font-smooth: always;
            }
            #canvas {
                width: 100%;
                height: 100vh;
                display: block;
            }
            .controls {
                position: absolute;
                top: 10px;
                left: 10px;
                background-color: #fff;
                padding: 10px;
                border: 1px solid #ddd;
                border-radius: 5px;
                box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            }
        </style>
    </head>
    <body>
        <canvas id="canvas"></canvas>
        <div class="controls">
            <label for="rotationSpeed">Rotation Speed:</label>
            <input type="range" id="rotationSpeed" min="0.01" max="0.1" step="0.01" value="0.05">
            <span id="rotationSpeedValue">0.05</span>
            <br>
            <label for="pointSize">Point Size:</label>
            <input type="range" id="pointSize" min="1" max="10" step="1" value="5">
            <span id="pointSizeValue">5</span>
            <br>
            <label for="numPoints">Number of Points:</label>
            <input type="range" id="numPoints" min="100" max="1000" step="100" value="500">
            <span id="numPointsValue">500</span>
            <br>
            <label for="colorR">Color R:</label>
            <input type="range" id="colorR" min="0" max="255" step="1" value="255">
            <span id="colorRValue">255</span>
            <br>
            <label for="colorG">Color G:</label>
            <input type="range" id="colorG" min="0" max="255" step="1" value="0">
            <span id="colorGValue">0</span>
            <br>
            <label for="colorB">Color B:</label>
            <input type="range" id="colorB" min="0" max="255" step="1" value="0">
            <span id="colorBValue">0</span>
        </div>
    
        <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
        <script>
            let scene, camera, renderer, points;
            let rotationSpeed = 0.05;
            let pointSize = 5;
            let numPoints = 500;
            let colorR = 255;
            let colorG = 0;
            let colorB = 0;
    
            init();
            animate();
    
            function init() {
                scene = new THREE.Scene();
                camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
                renderer = new THREE.WebGLRenderer({
                    canvas: document.getElementById('canvas'),
                    antialias: true
                });
                renderer.setSize(window.innerWidth, window.innerHeight);
    
                camera.position.z = 5;
    
                const geometry = new THREE.SphereGeometry(1, 60, 60);
                const material = new THREE.PointsMaterial({
                    size: pointSize,
                    color: new THREE.Color(`rgb(${colorR}, ${colorG}, ${colorB})`)
                });
    
                points = new THREE.Points(geometry, material);
                scene.add(points);
    
                document.getElementById('rotationSpeed').addEventListener('input', (e) => {
                    rotationSpeed = parseFloat(e.target.value);
                    document.getElementById('rotationSpeedValue').innerText = rotationSpeed;
                });
    
                document.getElementById('pointSize').addEventListener('input', (e) => {
                    pointSize = parseInt(e.target.value);
                    points.material.size = pointSize;
                    document.getElementById('pointSizeValue').innerText = pointSize;
                });
    
                document.getElementById('numPoints').addEventListener('input', (e) => {
                    numPoints = parseInt(e.target.value);
                    const newGeometry = new THREE.SphereGeometry(1, Math.ceil(Math.sqrt(numPoints)), Math.ceil(Math.sqrt(numPoints)));
                    points.geometry.dispose();
                    points.geometry = newGeometry;
                    document.getElementById('numPointsValue').innerText = numPoints;
                });
    
                document.getElementById('colorR').addEventListener('input', (e) => {
                    colorR = parseInt(e.target.value);
                    points.material.color = new THREE.Color(`rgb(${colorR}, ${colorG}, ${colorB})`);
                    document.getElementById('colorRValue').innerText = colorR;
                });
    
                document.getElementById('colorG').addEventListener('input', (e) => {
                    colorG = parseInt(e.target.value);
                    points.material.color = new THREE.Color(`rgb(${colorR}, ${colorG}, ${colorB})`);
                    document.getElementById('colorGValue').innerText = colorG;
                });
    
                document.getElementById('colorB').addEventListener('input', (e) => {
                    colorB = parseInt(e.target.value);
                    points.material.color = new THREE.Color(`rgb(${colorR}, ${colorG}, ${colorB})`);
                    document.getElementById('colorBValue').innerText = colorB;
                });
            }
    
            function animate() {
                requestAnimationFrame(animate);
                points.rotation.y += rotationSpeed;
                renderer.render(scene, camera);
            }
        </script>
    </body>
    </html>
    

    This code creates a rotating sphere of points with sliders for rotation speed, point size, number of points, and color. The init function sets up the scene, camera, renderer, and points, and adds event listeners to the sliders. The animate function is called repeatedly to update the rotation of the points and render the scene.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.