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

              
                <div></div>
              
            
!

CSS

              
                body {
  margin: 0;
}

canvas { 
  display: block;
}
              
            
!

JS

              
                function main() {
  // Init scene
  const scene = new THREE.Scene();
  
  // Init camera
  const [width, height] = [window.innerWidth, window.innerHeight];
  const fov = 75;
  const aspect = width/height;
  const near = 0.1;
  const far = 1000;
  const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);

  // Init renderer; attach to HTML canvas
  const renderer = new THREE.WebGLRenderer();
  renderer.setSize(width, height);
  document.body.appendChild(renderer.domElement);

  // Init light
  // Many lighting solutions in ThreeJS
  // point lights, directional lights, etc.
  const light = new THREE.HemisphereLight(
    0xffffbb,   // sky color
    0x080820, 	// ground color
    1 			    // intensity
  );
  scene.add(light);

  // Create geometry (width, height, depth), and materials
  const cubeGeo = new THREE.BoxGeometry(1,1,1);
  const redMat = new THREE.MeshPhongMaterial({color: 0xdd2244});

  const c1 = new THREE.Mesh(cubeGeo, redMat);
  c1.position.set(-2, 0, -5);
  scene.add(c1);

  // Geometries and meshes can be reused!
  const c2 = new THREE.Mesh(cubeGeo, redMat)
  c2.position.set(+2, 0, -5);
  scene.add(c2);

   // Keep track of objects for demo
  const cubes = [c1, c2];

  // Animation loop
  const renderLoop = (time_ms) => {
  	requestAnimationFrame(renderLoop);

  	cubes.forEach((cube, index) => {
       	  const speed = (1 + index) * .001;
        	const rot = time_ms * speed;
        	cube.rotation.x = rot;
        	cube.rotation.y = rot;
    });
    renderer.render(scene, camera);
  };
  
  // Setup callback(s)

  // Set callback to begin animation
  requestAnimationFrame(renderLoop);
  
  const resizeHandler = () => {
    // Grab new width and heights
    const [width, height] = [window.innerWidth, window.innerHeight];
    renderer.setSize(width, height);
    camera.aspect = width / height;
    camera.updateProjectionMatrix();
  }
  
  // Add resize handler
  window.addEventListener("resize", resizeHandler, false);
}



main();
              
            
!
999px

Console