Pen Settings



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


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


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.


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.


                <div id="world" />


                @import url(;

  background-color: #ffffff;
  font-family: "Open Sans";

	position: absolute;
	height: 100%;



                function update(){
  the angle is incremented by 0.1 every frame, try higher values for a faster animation
  angle += .1;
  Try modifying the angle and/or the radius for a different movement
  cube.position.x = cos(angle) * radius;
  cube.position.y = sin(angle) * radius;
  You may want to use the same principle on the rotation property of an object, uncomment the next line to see what happens
  //cube.rotation.z = cos(angle) * PI/4;
  Or act on the scale, note that 1 is added as an offset to avoid a negative scale value.
  //cube.scale.y = 1 + cos(angle) * .5;
  Your turn, you may want to:
  - comment or uncomment the lines above to try new combinations,
  - replace cos by sin and vice versa, 
  - replace radius with an other cyclic function 
  example : 
  cube.position.x = cos(angle) * (sin(angle) *radius);

The code below initializes the needed variables
and A Threejs scene. Though setting up a threejs scene is out of the scope of this article I added a few comments to understand what's happening there.

// initializing variables :
var scene, camera, renderer, WIDTH, HEIGHT;
var PI = Math.PI;
var angle = 0;
var radius = 10;
var cube;
var cos = Math.cos;
var sin = Math.sin;

function init(event) {
  // get the container that will hold the animation
  var container = document.getElementById('world');
  // get window size
  HEIGHT = window.innerHeight;
  WIDTH = window.innerWidth;
  // create a threejs Scene, set up the camera and the renderer
  scene = new THREE.Scene();  
  camera = new THREE.PerspectiveCamera( 50, WIDTH / HEIGHT, 1, 2000 );
  camera.position.z = 100;
  renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true });
  renderer.setSize(WIDTH, HEIGHT);
  renderer.setPixelRatio(window.devicePixelRatio ? window.devicePixelRatio : 1);
  // create the cubecube
  var geom = new THREE.CubeGeometry(16,8,8, 1);
  var material = new THREE.MeshStandardMaterial({
    color: 0x401A07
  cube = new THREE.Mesh(geom, material);
  // add the cube to the scene
  // create and add a light source
  var globalLight = new THREE.AmbientLight(0xffffff, 1);
  // listen to the window resize
  window.addEventListener('resize', handleWindowResize, false);
  // start a loop that will render the animation in each frame
function handleWindowResize() {
  // If the window is resized, we have to update the camera aspect ratio
  HEIGHT = window.innerHeight;
  WIDTH = window.innerWidth;
  renderer.setSize(WIDTH, HEIGHT);
  camera.aspect = WIDTH / HEIGHT;
function loop(){
  // call the update function in each frame to update the cube position
  // render the scene in each frame
  renderer.render(scene, camera);
  // call the loop function in next frame
// initialize the demo when the page is loaded
window.addEventListener('load', init, false);