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.


                <!-- My scene -->
	<canvas id="scene"></canvas>

  I created a collection of small examples in Three.js to understand very quickly the purpose of some functions.
  You can visit the 'website' of the entire collection of pens here :

  You can also see the collection in CodePen

  Do not hesitate to comment if there is something wrong (I'm still learning)

  Thanks !


                body,html, canvas{width:100%;height:100%;padding:0;margin:0;overflow: hidden;}



                var renderer, scene, camera, cube;

var ww = window.innerWidth,
	wh = window.innerHeight;

function init(){

	renderer = new THREE.WebGLRenderer({canvas : document.getElementById('scene')});

	scene = new THREE.Scene();

	camera = new THREE.PerspectiveCamera(50,ww/wh, 0.1, 10000 );

	//Add a light in the scene
	directionalLight = new THREE.DirectionalLight( 0xffffff, 0.8 );
	directionalLight.position.set( 0, 0, 350 );
	directionalLight.lookAt(new THREE.Vector3(0,0,0));
	scene.add( directionalLight );

	//Add a cube in the scene add apply animation

	//Render the scene and start request animation frame

var createCube = function(){

	//Create a new cube with simple geometry & material
	var geometry = new THREE.BoxGeometry(150,150,150);
	var texture = new THREE.MeshLambertMaterial({color:0x00ff00, transparent: true });
	cube = new THREE.Mesh(geometry, texture);

	//Create a new timeline
	//I like to add my timeline to my element object so I know to which element it refers to
	//But we could declare a new variable which contains the timeline = new TimelineMax({repeat:-1, repeatDelay: 1});
	//I add a few animations in my timeline
	//The cube turn on itself, 3, {y:-Math.PI*3.25, x : -Math.PI*1.25, ease:Back.easeInOut});

	//Then it will move to the left and fade out, 1, {x : -150, ease:Power3.easeOut});, 1, {opacity : 0, ease:Power3.easeOut}, "-=1");

	//Move the cube without transition,{x:100, y: -100});

	//Fade In the cube, 1, {opacity : 1, ease:Power3.easeOut});

	//It goes back to its initial position, 3, {x:0,y:0, ease: Back.easeInOut.config(2)});, 3, {x:0,y:0, ease: Back.easeInOut.config(2)},"-=3");

	//Add the cube in the scene

var render = function () {

	//Simply render the scene with a request animation frame and the timeline from GreenSock will do the rest ;)
	renderer.render(scene, camera);