Pen Settings

HTML

CSS

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

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/three.js/r54/three.js"></script>

<body>
  <div id=text >
    gingerman codepen 2 - using threejs to create some planes arranged in a circle altering the camera position and speed etc.
  </div>    
</body>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Raleway:900);
body {
  background: grey;
  color: white;
  text-align:center;
  font-family :Raleway;
}
              
            
!

JS

              
                

			var container, stats;
			var camera, scene, projector, renderer;
			var group;
			var rotationSpeed;
			var increment;
			var camPosIncrement;

			init();
			animate();

			function init() {

				rotationSpeed = 0.5;
				increment = 0.001;
				camPosIncrement = 2;

				container = document.createElement( 'div' );
				document.body.appendChild( container );

				

				camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 10000 );
        camera.position.x = 0;
				camera.position.y = 50;
				camera.position.z = 300;

				scene = new THREE.Scene();

				group = new THREE.Object3D();

        // try altering some of these doo daas
				makeCyinderOutOfPlanes( 40, 10, 800, scene, group )

				projector = new THREE.Projector();

				renderer = new THREE.CanvasRenderer();
				renderer.setSize( window.innerWidth, window.innerHeight );

				container.appendChild(renderer.domElement);

				//stats = new Stats();
				//stats.domElement.style.position = 'absolute';
				//stats.domElement.style.top = '0px';
				//container.appendChild( stats.domElement );


				//

			window.addEventListener( 'resize', onWindowResize, false );

			}




			function makeCyinderOutOfPlanes( numberOfPlanes, yPos, rad) {

	            for ( var p = 0; p < numberOfPlanes; p++ ) {

	            	console.log( "p = " + p );

	               var geometry = new THREE.PlaneGeometry( 100, 200, 1, 1  );
	               var randomCol = randomColour();

				   var meshMaterial = new THREE.MeshBasicMaterial( { color:0xffffff } );


	               var oThisPlaneObject = new THREE.Mesh( geometry, meshMaterial );
	               oThisPlaneObject.material.side = THREE.DoubleSide;

	                //
	                var planesProps = calculatePlaneProperties( p, numberOfPlanes, rad 	); 
	                //
	                oThisPlaneObject.position.x = planesProps[ 0 ];
	                oThisPlaneObject.position.y = yPos;
	                oThisPlaneObject.position.z = planesProps[ 1 ];

	               	var newRotYDegrees = ( ( 360 / numberOfPlanes ) * p  ) + 90;

	               	var newRotY =   newRotYDegrees * ( Math.PI / 180 );

	               	console.log( "rotation ( Radians ? ) = " + newRotY );

	                oThisPlaneObject.rotation.y = newRotY;

	                // add plane to container
	                group.add( oThisPlaneObject );
	            }

	           scene.add( group );
        	}



			function calculatePlaneProperties( planeNumber, totalPlanes, nRadius ) {

	            var planePropsArray = new Array();

	            var rotscaler = 2;// could not think of a better variable name =D steve

	            var qAngle = ( Math.PI * rotscaler / totalPlanes ) ;

	            
	            //Math.PI / 180

	            // translate the circular motion and position of the clip in question into distance 
	            var newx = - ( nRadius * Math.cos( qAngle * planeNumber ) );

	            var newz = nRadius*Math.sin( qAngle * planeNumber );

	            planePropsArray = new Array( newx, newz );//, newr );

	            return planePropsArray;
        	}


        	function randomColour(){
            
           	 	var randomCol = Math.random() * 0xFFFFFF;

            	return randomCol;

        	}





			function onWindowResize() {

				camera.aspect = window.innerWidth / window.innerHeight;
				camera.updateProjectionMatrix();

				renderer.setSize( window.innerWidth, window.innerHeight );

			}

			

			function animate() {

				requestAnimationFrame( animate );

				render();
			//	stats.update();

			}

			var radius = 600;
			var theta = 0;

			function render() {

				//TWEEN.update();

				theta += 0.5;

				camera.position.x = radius * Math.sin( THREE.Math.degToRad( theta ) );
				camera.position.y = radius * Math.sin( THREE.Math.degToRad( theta ) );
			camera.position.z = radius * Math.cos( THREE.Math.degToRad( theta ) );
				//scene.rotationX = scene.rotationX + 1;
				rotationSpeed = rotationSpeed - increment;
				
				camera.position.y = camera.position.y + camPosIncrement;
				
				if ( camera.position.y > 1000 ||  camera.position.y < -2000){
				    camPosIncrement = -camPosIncrement;
				}
				
				if ( rotationSpeed < 0.001 ){
					rotationSpeed = 0.001;
					increment = -0.001;
				} else if ( rotationSpeed > 0.1){
				    rotationSpeed = 0.1;
					increment = 0.001;
				}
				group.rotation.y = group.rotation.y + rotationSpeed;

				//console.log( "p = " + p );

				camera.lookAt( scene.position );

				renderer.render( scene, camera );

      }
              
            
!
999px

Console