Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

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 id="canvas"></div>

              
            
!

CSS

              
                body {
  margin: 0;
}


#canvas {
  width: 100%;
  height: 100%;
  background-color:#000;
  /*background-image: linear-gradient(red, yellow);*/
/*   background-image: linear-gradient(black, red); */
  background-image: linear-gradient(black, #222);
}
              
            
!

JS

              
                
/* Setup
-------------------------------------------- */

// Scene
var scene = new THREE.Scene();

// Camera
var camera = new THREE.PerspectiveCamera( 25, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.z = 14;
camera.position.y = 0;
// camera.lookAt(scene.position);

// Update Window
window.addEventListener("resize", onWindowResize, false);
function onWindowResize() {
  camera.aspect = window.innerWidth / window.innerHeight;
  camera.updateProjectionMatrix();
  renderer.setSize(window.innerWidth, window.innerHeight);
}

// Controls
var controls = new THREE.OrbitControls( camera, document.getElementById('canvas')[0] );
// controls = new THREE.OrbitControls(camera);
controls.enableZoom = false;
controls.enablePan = false;
controls.autoRotate = true;
controls.update();


/* Three Point Lighting
-------------------------------------------- */

pointLight = new THREE.PointLight(0xffffff, 1, 0);
pointLight.position.set(-2, 2, -3);
var sphereSize = 1;
var pointLightHelper = new THREE.PointLightHelper( pointLight, sphereSize );
//scene.add( pointLightHelper );
// scene.add(pointLight);

pointLight = new THREE.PointLight(0xffffff, 1, 0);
pointLight.position.set(2.5, 1, 0);
var sphereSize = 1;
var pointLightHelper = new THREE.PointLightHelper( pointLight, sphereSize );
//scene.add( pointLightHelper );
// scene.add(pointLight);

pointLight = new THREE.PointLight(0xffffff, 1, 0);
pointLight.position.set(-2, 0, 1);
var sphereSize = 1;
var pointLightHelper = new THREE.PointLightHelper( pointLight, sphereSize );
//scene.add( pointLightHelper );
//scene.add(pointLight);






/* Other Lights
-------------------------------------------- */

// Simple Directional Light
// dirLight = new THREE.DirectionalLight(0x00ff00);
// dirLight.position.set(-1, -1, -1);
// helper = new THREE.DirectionalLightHelper( dirLight, 1 );
// scene.add(helper);
// scene.add(dirLight);



// Directional Light with Shadow
dirLight = new THREE.DirectionalLight(0xffffff, 3);
dirLight.position.set(0, 4, 0);
dirLight.castShadow = true;
dirLight.shadow.mapSize.width = 222;
dirLight.shadow.mapSize.height = 555;
var d = 2;
dirLight.shadow.camera.left = -d;
dirLight.shadow.camera.right = d;
dirLight.shadow.camera.top = d;
dirLight.shadow.camera.bottom = -d;
dirLight.shadow.camera.far = 20;
dirLight.shadowDarkness = .2;
//helper = new THREE.DirectionalLightHelper( dirLight, 1 );
//scene.add(helper);
scene.add(dirLight);




// Spot Light with Shadow
spotLight = new THREE.SpotLight(0xffffff, 2);
spotLight.position.set(0, 4, 0);
spotLight.castShadow = true;
spotLight.shadow.mapSize.width = 222;
spotLight.shadow.mapSize.height = 999;
var d = 2;
spotLight.shadow.camera.left = -d;
spotLight.shadow.camera.right = d;
spotLight.shadow.camera.top = d;
spotLight.shadow.camera.bottom = -d;
spotLight.shadow.camera.far = 1;

//spotLight.shadowDarkness = 1;
//helper = new THREE.DirectionalLightHelper( spotLight, 1 );
//scene.add(helper);
//scene.add(spotLight);





/* Objects
-------------------------------------------- */

// Plane
var planeGeometry = new THREE.BoxGeometry( 24, .1, 24 );
var planeMaterial = new THREE.MeshPhongMaterial( { color: 0xffffff } );
var plane = new THREE.Mesh( planeGeometry, planeMaterial );
plane.position.y = -3;
//plane.receiveShadow = true;
scene.add( plane );

// Cube
var cubeGeometry = new THREE.BoxGeometry( 1, 1, 1 );
var cubeMaterial = new THREE.MeshPhongMaterial( { color: 0xffffff } );

// Cube 1
var cube = new THREE.Mesh( cubeGeometry, cubeMaterial );
// cube.position.y = .5;
cube.scale = .5;
//cube.castShadow = true;
cube.receiveShadow = true;
scene.add( cube );

// Cube 2
var cube2 = new THREE.Mesh( cubeGeometry, cubeMaterial );
// cube2.position.y = .57;
cube2.scale = .5;
//cube2.castShadow = true;
cube2.receiveShadow = true;
scene.add(cube2);







/* Animation
-------------------------------------------- */


// cube

cube.tl = new TimelineMax({repeat:-1, yoyo: true, ease: Power1.easeInOut });
cube.tl.to(cube.rotation, 6, {
  y:-Math.PI*3.25, 
  x: -Math.PI*1.25, 
});

cube.tl2 = new TimelineMax({repeat:-1, yoyo: true, ease: Power1.easeInOut });
cube.tl2.to(cube.scale, 5, {
  x:1.5,
  y:1.5,
  z:1.5,
});


// cube 2

cube2.tl = new TimelineMax({repeat:-1, yoyo: true, ease: Power1.easeInOut, delay:.5 });
cube2.tl.to(cube2.rotation, 6, {
  y:-Math.PI*3.25, 
  x: -Math.PI*1.25, 
});

cube2.tl2 = new TimelineMax({repeat:-1, yoyo: true, ease: Power1.easeInOut });
cube2.tl2.to(cube2.scale, 5, {
  x:1.5,
  y:1.5,
  z:1.5,
});






/* Render
-------------------------------------------- */

container = document.getElementById( 'canvas' );

// Renderer
var renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.shadowMap.enabled = true;
container.appendChild( renderer.domElement );

// Render
var render = function() {
  requestAnimationFrame(render);
  renderer.render(scene, camera);
  controls.update();
};

render();
              
            
!
999px

Console