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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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.

            
              * {
  margin: 0;
  padding: 0;
}
.container {
  height: 100%;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
}
body {
  background-size: cover;
  height: 100vh;
  width: 100vw;
	background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAFCAYAAACXU8ZrAAAAt0lEQVQYVwXBv07CQADA4d/1+icFrTRlYcKJUcPqTJyU8AYusLg54mbCM/AaPIaJkwsLi4kLaWAwFnrntXfn94nnm7UPEkWtK4pejKJBh5KynzN9feB984GY36+8MJ7MpWAajP3DRTGHrEtnPEId94jF7crrqwHYkjyGtBMQiIjfGn7OITJpEbPrpZ88PXL6/mL3uaVNFJaQ6LIg9oK0jhAvd2/eNjmBc+DO1EaRSonXF5hhjrIV/8SlRXbflbkFAAAAAElFTkSuQmCC");
}
            
          
!
            
              let renderer;
let camera;
let controls;
let scene;

const NUM_SLICES = 40;

function init() {
	const container = document.getElementsByClassName('container')[0];
	const w = container.offsetWidth;
	const h = container.offsetHeight;
	
	renderer = new THREE.WebGLRenderer({antialias: true, alpha: true});
	renderer.setSize(w, h);
	// renderer.setClearColor(0xEFEFEF);
	renderer.setPixelRatio(window.devicePixelRatio)
	container.appendChild(renderer.domElement);
	
	scene = new THREE.Scene();
	
	camera = new THREE.PerspectiveCamera(15, w/h, 1, 1000);
	camera.position.set(7, 4, 0);
	camera.lookAt(scene.position);
	
	controls = new THREE.OrbitControls( camera, renderer.domElement );
	//controls.addEventListener( 'change', render ); // add this only if there is no animation loop (requestAnimationFrame)
	controls.enableDamping = true;
	controls.dampingFactor = 0.2;
	controls.rotateSpeed = 0.3;
	
  const topLight = new THREE.DirectionalLight(0xFFFFFF, 1);
  const leftLight = new THREE.DirectionalLight(0xFFFFFF, 0.5);
  const rightLight = new THREE.DirectionalLight(0xFFFFFF, 0.5);
  const sideLightOffset = 0
  topLight.position.set(0, 2, 0);
  leftLight.position.set(sideLightOffset, 0, 2);
  leftLight.lookAt(new THREE.Vector3(sideLightOffset, 0, 0))
  rightLight.position.set(sideLightOffset, 0, -2);
  rightLight.lookAt(new THREE.Vector3(sideLightOffset, 0, 0))
  const ambientLight = new THREE.AmbientLight(0x111111);
	
	scene.add(topLight);
  scene.add(leftLight);
  scene.add(rightLight);
  scene.add(ambientLight);
	
	scene.add(camera);
	
	render();
}

function render() {
	window.requestAnimationFrame(render);
	renderer.render(scene, camera);
	controls.update();
}

function slicedCube() {
  const container = new THREE.Object3D();
  const slices = new Array(NUM_SLICES).fill(1).map((item, index) => {
    item = new THREE.Mesh(
      new THREE.BoxGeometry(1/NUM_SLICES,1,1), 
      new THREE.MeshNormalMaterial(1,1,1)
      // new THREE.MeshLambertMaterial({
      //   color: 0xFAFAFA,
      //   ambient: 0x222222
      // })
    );
    item.position.set(index*(1/NUM_SLICES) - (0.5 - 1/NUM_SLICES/2), 0, 0)
    container.add(item);
    return item;
  });
  container.rotation.set(0, Math.PI/4, 0);
  scene.add(container);
  rotateAnim(container);
  slicesAnim(slices);
}

function rotateAnim(object) {
  TweenMax.to(object.rotation, 4, {
    // y: Math.PI*2 + Math.PI/4,
    y: (3 * Math.PI)/4,
    repeat: -1,
    ease: Power0.easeNone
  })
}

function slicesAnim(slices) {
  const tl = new TimelineMax({repeat: -1});
  const duration = 1;
  slices.forEach((slice, index) => {
    tl.to(slice.rotation, 1, {
      x: index%2 === 0 ? Math.PI/2 : -Math.PI/2,
      ease: Power2.easeInOut
    }, `-=0.99`)
  });
  tl.duration(4).play();
}

init();
slicedCube();

window.addEventListener('resize', function() {
	renderer.setSize(window.innerWidth, window.innerHeight);
	camera.aspect = window.innerWidth / window.innerHeight;
	camera.updateProjectionMatrix();
}, false);
            
          
!
999px
Loading ..................

Console