cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

              @import url(https://fonts.googleapis.com/css?family=Open+Sans:600);

  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);

Loading ..................