Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <canvas id="myCanvas"></canvas>
              
            
!

CSS

              
                body {
  margin: 0;
  background-image: radial-gradient(#494067, #030D14);
}
              
            
!

JS

              
                  window.addEventListener('load', Resize);
  window.addEventListener('resize', Resize);
  
  let width = 100, height = 100;

  function Resize() {

    let width = window.innerWidth,
        height = window.innerHeight,
        rot = 0;

    /**
    * renderer
    **/
    const renderer = new THREE.WebGLRenderer({
      canvas: document.querySelector('#myCanvas'),
      alpha: true
    });
    renderer.setPixelRatio(window.devicePixelRatio);
    renderer.setSize(width, height);
    renderer.shadowMap.enabled = true;

    /**
    * scene
    **/
    const scene = new THREE.Scene();

    /**
    * camera
    **/
    const camera = new THREE.PerspectiveCamera(45, width / height);
    camera.position.set(0, 160, +1000);

    /**
    * controls
    **/
    const controls = new THREE.OrbitControls(camera, document.body);

    /**
    * dumpling
    **/
    const geometry = new THREE.SphereBufferGeometry(40, 40, 40);
    const dumpling = new THREE.MeshPhongMaterial({color: 0xE6E1CA});

    for (let li = 0; li <= 13; li++){
      const dumpling_box = new THREE.Mesh(geometry, dumpling);
      switch (true) {
        case li === 0:
          dumpling_box.position.set(0, 240, 0);
          break;
        case li === 1:
          dumpling_box.position.set(-40, 180, -40);
          break;
        case li === 2:
          dumpling_box.position.set(40, 180, -40);
          break;
        case li === 3:
          dumpling_box.position.set(-40, 180, 40);
          break;
        case li === 4:
          dumpling_box.position.set(40, 180, 40);
          break;
        case li === 5:
          dumpling_box.position.set(-80, 120, 80);
          break;
        case li === 6:
          dumpling_box.position.set(0, 120, 80);
          break;
        case li === 7:
          dumpling_box.position.set(80, 120, 80);
          break;
        case li === 8:
          dumpling_box.position.set(-80, 120, 0);
          break;
        case li === 9:
          dumpling_box.position.set(80, 120, 0);
          break;
        case li === 10:
          dumpling_box.position.set(80, 120, -80);
          break;
        case li === 11:
          dumpling_box.position.set(0, 120, -80);
          break;
        case li === 12:
          dumpling_box.position.set(-80, 120, -80);
          break;
        default:       
          dumpling_box.position.set(0, 120, 0);
          break;
      }
      scene.add(dumpling_box);
    }

    /**
    * box
    **/
    const box_top = new THREE.CylinderGeometry(200, 200, 50, 8);
    const box_material = new THREE.MeshPhongMaterial({color: 0xd0b893});
    const box_mesh = new THREE.Mesh(box_top, box_material);
    box_mesh.position.set(0, 60, 0);
    scene.add(box_mesh);

    /**
    * box_ring
    **/
    const box_ring = new THREE.TorusGeometry( 190, 10, 5, 8 );
    const box_ring_material = new THREE.MeshPhongMaterial({color: 0xd0b893});
    const box_ring_mesh = new THREE.Mesh( box_ring, box_ring_material );
    box_ring_mesh.position.set(0, 90, 0);
    box_ring_mesh.rotation.set(Math.PI/2, 0, 0);
    scene.add( box_ring_mesh );

    /**
    * box_bottom
    **/
    const box_bottom = new THREE.CylinderGeometry(120, 120, 200, 8);
    const box_bottom_material = new THREE.MeshPhongMaterial({color: 0xd0b893});
    const box_bottom_mesh = new THREE.Mesh(box_bottom, box_bottom_material);
    box_bottom_mesh.position.set(0, -40, 0);
    scene.add( box_bottom_mesh );

    /**
    * moon
    **/
    const moon = new THREE.SphereBufferGeometry( 50, 50, 50 );
    const moon_texture = new THREE.TextureLoader().load('https://threejs-plactice.vercel.app/earth/img/moon.jpg');
    const moon_materials = new THREE.MeshStandardMaterial( { color: 0xffffff, map:moon_texture } );
    const moon_box_mesh = new THREE.Mesh( moon, moon_materials );
    moon_box_mesh.position.set(100, 400, -1000);
    scene.add(moon_box_mesh);

    /**
    * fragment
    **/
    createStarField();
    function createStarField() {
      const geometry = new THREE.SphereBufferGeometry(3, 3, 3),
            size = 1;
      for (let i = 0; i < 1000; i++) {
        const material = new THREE.MeshPhongMaterial({
          color: 0xffffff,
          flatShading: true
        })
        const mesh = new THREE.Mesh(geometry, material)
        mesh.position.set(1 * Math.random() - 0.5, 1 * Math.random() - 0.5 , 1 * Math.random() - 0.5 ).normalize()
        mesh.position.multiplyScalar(Math.random() * 1500)
        mesh.rotation.set(Math.random() * 2, Math.random() * 2, Math.random() * 2)
        mesh.scale.x = mesh.scale.y = mesh.scale.z = Math.random() * 1
        scene.add(mesh)
      }
    }

    /**
    * plane
    **/
    const plane = new THREE.PlaneGeometry(3000, 3000, 64, 64);
    const material = new THREE.MeshStandardMaterial( {color: 0xd0b893, side: THREE.DoubleSide} );
    const plane_box =  new THREE.Mesh( plane, material );
    plane_box.position.set(0, -150, 0);
    plane_box.rotation.set(-Math.PI/2, 0, 0);
    scene.add(plane_box);   

    /**
    * light
    **/
    const directionalLight = new THREE.DirectionalLight(0xE8CE88);
    directionalLight.position.set(0, 1, 1);
    scene.add(directionalLight);
    
    /**
    * pointLight
    **/
    const pointLight = new THREE.PointLight(0xE8CE88, 2, 1000);
    scene.add(pointLight);

    tick();

    function tick() {
      scene.rotation.y -= 0.01;
      renderer.render(scene, camera);
      requestAnimationFrame(tick);
    }
  }
              
            
!
999px

Console