123

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div id="container"></div>
<div class="info">
  <a href="http://gif.flrn.nl/post/116405047507">Original gif by Flrn</a>
  <p>Made by <a href="http://vdaguenet.fr">Valentin Daguenet</a></p>
</div>
            
          
!
            
              body,
html {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

p,
a {
  font-family: Helvetica;
  font-size: 12px;
  margin: 0;
  padding: 0;
}

p {
  color: #bdbdbd;
}

a {
  color: white;
  opacity: 0.7;
  text-decoration: none;
  transition: opacity 0.4s;
}

a:hover {
  opacity: 1;
}

.info {
  position: absolute;
  bottom: 20px;
  right: 20px;
  text-align: right;
}
            
          
!
            
              (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}var _objectsCube=require("./objects/Cube");var _objectsCube2=_interopRequireDefault(_objectsCube);var CONTAINER_HALF_WIDTH=60;var Webgl=function(){function Webgl(width,height){_classCallCheck(this,Webgl);this.width=width;this.height=height;this.scene=new THREE.Scene;this.camera=new THREE.OrthographicCamera(width/-2,width/2,height/2,height/-2,1,1e3);this.camera.position.z=300;this.camera.lookAt(new THREE.Vector3(0,0,0));this.renderer=new THREE.WebGLRenderer({antialias:true});this.renderer.setSize(width,height);this.renderer.setClearColor(2500134);this.initLights();this.cubeContainer=new THREE.Object3D;this.initCubes();this.cubeContainer.rotation.x=.196*Math.PI;this.cubeContainer.rotation.y=.25*Math.PI;this.scene.add(this.cubeContainer)}_createClass(Webgl,[{key:"initCubes",value:function initCubes(){var coords=[{x:-CONTAINER_HALF_WIDTH,y:CONTAINER_HALF_WIDTH,z:CONTAINER_HALF_WIDTH},{x:-CONTAINER_HALF_WIDTH,y:CONTAINER_HALF_WIDTH,z:-CONTAINER_HALF_WIDTH},{x:CONTAINER_HALF_WIDTH,y:CONTAINER_HALF_WIDTH,z:-CONTAINER_HALF_WIDTH},{x:CONTAINER_HALF_WIDTH,y:CONTAINER_HALF_WIDTH,z:CONTAINER_HALF_WIDTH},{x:CONTAINER_HALF_WIDTH,y:-CONTAINER_HALF_WIDTH,z:CONTAINER_HALF_WIDTH},{x:-CONTAINER_HALF_WIDTH,y:-CONTAINER_HALF_WIDTH,z:CONTAINER_HALF_WIDTH},{x:-CONTAINER_HALF_WIDTH,y:-CONTAINER_HALF_WIDTH,z:-CONTAINER_HALF_WIDTH},{x:CONTAINER_HALF_WIDTH,y:-CONTAINER_HALF_WIDTH,z:-CONTAINER_HALF_WIDTH}];var cube=undefined;for(var i=0;i<8;i++){cube=new _objectsCube2["default"];cube.position.set(coords[i].x,coords[i].y,coords[i].z);this.cubeContainer.add(cube)}}},{key:"reset",value:function reset(){this.scene.children.splice(1,1);for(var i=undefined,l=this.cubeContainer.children.length;i<l;i++){delete this.cubeContainer.children[i]}delete this.cubeContainer;this.camera=new THREE.OrthographicCamera(this.width/-2,this.width/2,this.height/2,this.height/-2,1,1e3);this.camera.position.z=300;this.camera.lookAt(new THREE.Vector3(0,0,0));this.cubeContainer=new THREE.Object3D;this.initCubes();this.cubeContainer.rotation.x=.196*Math.PI;this.cubeContainer.rotation.y=.25*Math.PI;this.scene.add(this.cubeContainer)}},{key:"rotateContainer",value:function rotateContainer(){var oldRot=this.cubeContainer.rotation.y;TweenMax.to(this.cubeContainer.rotation,.7,{y:oldRot+.5*Math.PI,ease:Cubic.easeOut})}},{key:"rotateCubes",value:function rotateCubes(){for(var i in this.cubeContainer.children){this.cubeContainer.children[i].rotate()}}},{key:"rotateCamera",value:function rotateCamera(){var oldRot=this.camera.rotation.z;TweenMax.to(this.camera.rotation,.7,{z:oldRot-.333*Math.PI,ease:Cubic.easeOut})}},{key:"initLights",value:function initLights(){this.light=new THREE.AmbientLight(16777215);this.scene.add(this.light)}},{key:"resize",value:function resize(width,height){this.width=width;this.height=height;this.camera.aspect=width/height;this.renderer.setSize(width,height)}},{key:"render",value:function render(){this.renderer.render(this.scene,this.camera)}}]);return Webgl}();exports["default"]=Webgl;module.exports=exports["default"]},{"./objects/Cube":2}],2:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();var _get=function get(_x,_x2,_x3){var _again=true;_function:while(_again){var object=_x,property=_x2,receiver=_x3;desc=parent=getter=undefined;_again=false;var desc=Object.getOwnPropertyDescriptor(object,property);if(desc===undefined){var parent=Object.getPrototypeOf(object);if(parent===null){return undefined}else{_x=parent;_x2=property;_x3=receiver;_again=true;continue _function}}else if("value"in desc){return desc.value}else{var getter=desc.get;if(getter===undefined){return undefined}return getter.call(receiver)}}};function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass)}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)subClass.__proto__=superClass}var Cube=function(_THREE$Object3D){function Cube(){_classCallCheck(this,Cube);_get(Object.getPrototypeOf(Cube.prototype),"constructor",this).call(this);var materials=[new THREE.MeshPhongMaterial({color:15548473,shading:THREE.FlatShading}),new THREE.MeshPhongMaterial({color:15548473,shading:THREE.FlatShading}),new THREE.MeshPhongMaterial({color:16690451,shading:THREE.FlatShading}),new THREE.MeshPhongMaterial({color:16690451,shading:THREE.FlatShading}),new THREE.MeshPhongMaterial({color:2138282,shading:THREE.FlatShading}),new THREE.MeshPhongMaterial({color:2138282,shading:THREE.FlatShading})];this.geom=new THREE.BoxGeometry(60,60,60);this.mat=new THREE.MeshFaceMaterial(materials);this.mesh=new THREE.Mesh(this.geom,this.mat);this.add(this.mesh)}_inherits(Cube,_THREE$Object3D);_createClass(Cube,[{key:"rotate",value:function rotate(){var oldRot=this.rotation.z;TweenMax.to(this.rotation,.7,{z:oldRot-.5*Math.PI,ease:Cubic.easeOut})}},{key:"reset",value:function reset(){this.rotation.set(0,0,0);this.mesh.rotation.set(0,0,0)}}]);return Cube}(THREE.Object3D);exports["default"]=Cube;module.exports=exports["default"]},{}],3:[function(require,module,exports){var process=module.exports={};var queue=[];var draining=false;var currentQueue;var queueIndex=-1;function cleanUpNextTick(){draining=false;if(currentQueue.length){queue=currentQueue.concat(queue)}else{queueIndex=-1}if(queue.length){drainQueue()}}function drainQueue(){if(draining){return}var timeout=setTimeout(cleanUpNextTick);draining=true;var len=queue.length;while(len){currentQueue=queue;queue=[];while(++queueIndex<len){currentQueue[queueIndex].run()}queueIndex=-1;len=queue.length}currentQueue=null;draining=false;clearTimeout(timeout)}process.nextTick=function(fun){var args=new Array(arguments.length-1);if(arguments.length>1){for(var i=1;i<arguments.length;i++){args[i-1]=arguments[i]}}queue.push(new Item(fun,args));if(queue.length===1&&!draining){setTimeout(drainQueue,0)}};function Item(fun,array){this.fun=fun;this.array=array}Item.prototype.run=function(){this.fun.apply(null,this.array)};process.title="browser";process.browser=true;process.env={};process.argv=[];process.version="";process.versions={};function noop(){}process.on=noop;process.addListener=noop;process.once=noop;process.off=noop;process.removeListener=noop;process.removeAllListeners=noop;process.emit=noop;process.binding=function(name){throw new Error("process.binding is not supported")};process.cwd=function(){return"/"};process.chdir=function(dir){throw new Error("process.chdir is not supported")};process.umask=function(){return 0}},{}],4:[function(require,module,exports){!function(name,definition){if(typeof module!="undefined")module.exports=definition();else if(typeof define=="function"&&typeof define.amd=="object")define(definition);else this[name]=definition()}("domready",function(){var fns=[],listener,doc=document,hack=doc.documentElement.doScroll,domContentLoaded="DOMContentLoaded",loaded=(hack?/^loaded|^c/:/^loaded|^i|^c/).test(doc.readyState);if(!loaded)doc.addEventListener(domContentLoaded,listener=function(){doc.removeEventListener(domContentLoaded,listener);loaded=1;while(listener=fns.shift())listener()});return function(fn){loaded?setTimeout(fn,0):fns.push(fn)}})},{}],5:[function(require,module,exports){var now=require("performance-now"),global=typeof window==="undefined"?{}:window,vendors=["moz","webkit"],suffix="AnimationFrame",raf=global["request"+suffix],caf=global["cancel"+suffix]||global["cancelRequest"+suffix];for(var i=0;i<vendors.length&&!raf;i++){raf=global[vendors[i]+"Request"+suffix];caf=global[vendors[i]+"Cancel"+suffix]||global[vendors[i]+"CancelRequest"+suffix]}if(!raf||!caf){var last=0,id=0,queue=[],frameDuration=1e3/60;raf=function(callback){if(queue.length===0){var _now=now(),next=Math.max(0,frameDuration-(_now-last));last=next+_now;setTimeout(function(){var cp=queue.slice(0);queue.length=0;for(var i=0;i<cp.length;i++){if(!cp[i].cancelled){try{cp[i].callback(last)}catch(e){setTimeout(function(){throw e},0)}}}},Math.round(next))}queue.push({handle:++id,callback:callback,cancelled:false});return id};caf=function(handle){for(var i=0;i<queue.length;i++){if(queue[i].handle===handle){queue[i].cancelled=true}}}}module.exports=function(fn){return raf.call(global,fn)};module.exports.cancel=function(){caf.apply(global,arguments)}},{"performance-now":6}],6:[function(require,module,exports){(function(process){(function(){var getNanoSeconds,hrtime,loadTime;if(typeof performance!=="undefined"&&performance!==null&&performance.now){module.exports=function(){return performance.now()}}else if(typeof process!=="undefined"&&process!==null&&process.hrtime){module.exports=function(){return(getNanoSeconds()-loadTime)/1e6};hrtime=process.hrtime;getNanoSeconds=function(){var hr;hr=hrtime();return hr[0]*1e9+hr[1]};loadTime=getNanoSeconds()}else if(Date.now){module.exports=function(){return Date.now()-loadTime};loadTime=Date.now()}else{module.exports=function(){return(new Date).getTime()-loadTime};loadTime=(new Date).getTime()}}).call(this)}).call(this,require("_process"))},{_process:3}],7:[function(require,module,exports){"use strict";function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}var _domready=require("domready");var _domready2=_interopRequireDefault(_domready);var _Webgl=require("./Webgl");var _Webgl2=_interopRequireDefault(_Webgl);var _raf=require("raf");var _raf2=_interopRequireDefault(_raf);var webgl=undefined;(0,_domready2["default"])(function(){webgl=new _Webgl2["default"](window.innerWidth,window.innerHeight);document.getElementById("container").appendChild(webgl.renderer.domElement);window.onresize=resizeHandler;animate()});function resizeHandler(){webgl.resize(window.innerWidth,window.innerHeight)}function animate(){var start=0;var tl=new TimelineMax({repeat:-1});tl.add(function(){webgl.rotateCamera()},start+0);tl.add(function(){webgl.rotateContainer()},start+.7);tl.add(function(){webgl.rotateCamera()},start+1.4);tl.add(function(){webgl.rotateCubes()},start+2.1);tl.add(function(){webgl.reset()},start+2.8);render()}function render(){(0,_raf2["default"])(render);webgl.render()}},{"./Webgl":1,domready:4,raf:5}]},{},[7]);
            
          
!
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.

Console