<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>3D Dodecahedron</title>
  <style>
    body {
      margin: 0;
      overflow: hidden;
      background: black;
    }
  </style>
</head>
<body>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
  <script>
    // Scene
    const scene = new THREE.Scene();

    // Camera
    const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
    camera.position.z = 5;

    // Renderer
    const renderer = new THREE.WebGLRenderer();
    renderer.setSize(window.innerWidth, window.innerHeight);
    document.body.appendChild(renderer.domElement);

    // Dodecahedron Geometry
    const geometry = new THREE.DodecahedronGeometry(2); // Dodecahedron with radius 2

    // Material with random colors
    const material = new THREE.MeshStandardMaterial({ vertexColors: true });

    // Add colors to faces
    const colors = [];
    for (let i = 0; i < geometry.attributes.position.count; i++) {
      colors.push(Math.random(), Math.random(), Math.random());
    }
    geometry.setAttribute('color', new THREE.Float32BufferAttribute(colors, 3));

    // Create the Mesh
    const dodecahedron = new THREE.Mesh(geometry, material);
    scene.add(dodecahedron);

    // Lighting
    const light = new THREE.PointLight(0xffffff, 1, 100);
    light.position.set(10, 10, 10);
    scene.add(light);

    // Animation loop
    function animate() {
      requestAnimationFrame(animate);
      dodecahedron.rotation.x += 0.01; // Rotate around X-axis
      dodecahedron.rotation.y += 0.01; // Rotate around Y-axis
      renderer.render(scene, camera);
    }

    animate(); // Start animation
  </script>
</body>
</html>

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.