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{width:100%;height:100%;padding:0;margin:0;overflow: hidden;}


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

function init(){

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

	/* SCENE */
	scene = new THREE.Scene();

	/* CAMERA */
	camera = new THREE.OrthographicCamera(ww/-2,ww/2,wh/2,wh/-2,0,1000);
	camera.position.set(0, 0, 500);

	/* LIGHT */
	light = new THREE.DirectionalLight(0xffffff, 1);
	light.position.set( 0, 250, 700 );

	//particles will be the 3D object containing all the particles
	particles = new THREE.Object3D();;

	//Add events listeners on the page
	document.addEventListener("mousemove", mouseMove);
	document.addEventListener("touchemove", mouseMove);


	//Init request animation frame

//Init var with mouse position
var mouse = {x:0,y:0};
function mouseMove(e){

	//3D universe come from the center so I substract half of the screen on the mouse position
	//By doing that, the cursor on the left will give -window/2 and on the right window/2
	//For the Y axis it's a bit different because the top equal 0 but in the scene the top is the positive side
	mouse.x = e.clientX-(ww/2);
	mouse.y = (wh/2)-e.clientY;


function createParticle(){

	//Create a geometry used for the particles which contains nothing for now
	var geometry = new THREE.Geometry();
	//Create a vector which equal to the mouse position
	var vertices = new THREE.Vector3(
	//We apply our vector inside the geometry
	//We create a white material
	//sizeAttenuation defines if the particle will be small if far from the camera
	var material = new THREE.PointsMaterial({
		color : 0X00ff00,
		size : 3,
		transparent : true,
		sizeAttenuation : false
    //Point cloud is a specific Mesh for particles
	particle = new THREE.Points(geometry, material);
	//We create a random speed for each particle for aesthetics
	particle.speed = Math.random()/100+0.002
	//We set a random position for each particle
	particle.direction = {
		x : (Math.random()-.5)*ww*2,
		y : (Math.random()-.5)*wh*2

var animate = function () {

	//Create a new particle

	//We loop through all our particles
	for(var i=0,j=particles.children.length;i<j;i++){
		//Get the next particle
		var particle = particles.children[i];

		//We move our particle closer to its destination
		particle.geometry.vertices[0].x += (particle.direction.x - particle.geometry.vertices[0].x)*particle.speed;
		particle.geometry.vertices[0].y += (particle.direction.y - particle.geometry.vertices[0].y)*particle.speed;
		//We reduce the opacity of the particle
		particle.material.opacity -= .005
		//Prevents ThreeJs the particle has moved
		particle.geometry.verticesNeedUpdate = true;

		//If the opacity of the particle is too low
		if(particle.material.opacity < .05){
			//We remove our particle from the scene
			//The loop must go through the same 'i' because we removed one particle from the array

	renderer.render(scene, camera);