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.

+ 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.

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

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

#world{
	position: absolute;
	width:100%;
	height: 100%;
  overflow:hidden;
}

            
          
!
            
              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);
  container.appendChild(renderer.domElement);
  // 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
  scene.add(cube);
  // create and add a light source
  var globalLight = new THREE.AmbientLight(0xffffff, 1);
  scene.add(globalLight);
  // listen to the window resize
  window.addEventListener('resize', handleWindowResize, false);
  // start a loop that will render the animation in each frame
  loop();
}
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;
  camera.updateProjectionMatrix();
}
function loop(){
  // call the update function in each frame to update the cube position
  update();
  // render the scene in each frame
  renderer.render(scene, camera);
  // call the loop function in next frame
  requestAnimationFrame(loop);
}
// initialize the demo when the page is loaded
window.addEventListener('load', init, false);


            
          
!
999px
🕑 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.
Loading ..................

Console