Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

  <script type="text/javascript" language="JavaScript1.5" src=""></script>
  <script type="text/javascript" language="JavaScript1.5" src=""></script>
  <script type="text/javascript" language="JavaScript1.5" src=""></script>
  <script type="text/javascript" language="JavaScript1.5" src=""></script>
  <div id="WebGL-output"></div>
  margin: 0;
  overflow: hidden;
              $(function () {

        var stats = initStats();

        // create a scene, that will hold all our elements such as objects, cameras and lights.
        var scene = new THREE.Scene();
        //scene.fog=new THREE.FogExp2( 0xffffff, 0.015 );
        scene.fog=new THREE.Fog( 0xffffff, 0.015, 100 );

        // create a camera, which defines where we're looking at.
        var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);

        // create a render and set the size
        var renderer = new THREE.WebGLRenderer();

        renderer.setClearColorHex(0xEEEEEE, 1.0);
        renderer.setSize(window.innerWidth, window.innerHeight);
        renderer.shadowMapEnabled = true;

        // create the ground plane
        var planeGeometry = new THREE.PlaneGeometry(60,40,1,1);
        var planeMaterial =    new THREE.MeshLambertMaterial({color: 0xffffff});
        var plane = new THREE.Mesh(planeGeometry,planeMaterial);
        plane.receiveShadow  = true;

        // rotate and position the plane

        // add the plane to the scene

        // position and point the camera to the center of the scene
        camera.position.x = -30;
        camera.position.y = 40;
        camera.position.z = 30;

        // add subtle ambient lighting
        var ambientLight = new THREE.AmbientLight(0x0c0c0c);

        // add spotlight for the shadows
        var spotLight = new THREE.SpotLight( 0xffffff );
        spotLight.position.set( -40, 60, -10 );
        spotLight.castShadow = true;
        scene.add( spotLight );

        // add the output of the renderer to the html element

        // call the render function
        var step=0;

        var controls = new function() {
            this.rotationSpeed = 0.02;
            this.numberOfObjects = scene.children.length;

            this.removeCube = function() {
                var allChildren = scene.children;
                var lastObject = allChildren[allChildren.length-1];
                if (lastObject instanceof THREE.Mesh) {
                    this.numberOfObjects = scene.children.length;

            this.addCube = function() {

                var cubeSize = Math.ceil((Math.random() * 3));
                var cubeGeometry = new THREE.CubeGeometry(cubeSize,cubeSize,cubeSize);
                var cubeMaterial = new THREE.MeshLambertMaterial({color:  Math.random() * 0xffffff });
                var cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
                cube.castShadow = true;

                // position the cube randomly in the scene
                cube.position.x=-30 + Math.round((Math.random() * planeGeometry.width));
                cube.position.y= Math.round((Math.random() * 5));
                cube.position.z=-20 + Math.round((Math.random() * planeGeometry.height));

                // add the cube to the scene
                this.numberOfObjects = scene.children.length;

            this.outputObjects = function() {

        var gui = new dat.GUI();
        gui.add(controls, 'rotationSpeed',0,0.5);
        gui.add(controls, 'addCube');
        gui.add(controls, 'removeCube');
        gui.add(controls, 'outputObjects');
        gui.add(controls, 'numberOfObjects').listen();


        function render() {

            // rotate the cubes around its axes
            scene.traverse(function(e) {
                if (e instanceof THREE.Mesh && e != plane ) {


            // render using requestAnimationFrame
            renderer.render(scene, camera);

        function initStats() {

            var stats = new Stats();

            stats.setMode(0); // 0: fps, 1: ms

            // Align top-left
   = 'absolute';
   = '0px';
   = '0px';

            $("#Stats-output").append( stats.domElement );

            return stats;
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.