gibney.org
:
Technology
:
Javascript
:
Experiments
:
three.js example
(Entry Nr. 2085, by user 1 |
edit
)
<html><body> <script src="http://mrdoob.github.com/three.js/examples/js/RequestAnimationFrame.js"></script> <script src="http://mrdoob.github.com/three.js/build/Three.js"></script> <script> var camera, scene, renderer, geometry, material, mesh; init(); animate(); function init() { camera = new THREE.Camera( 75, window.innerWidth / window.innerHeight, 1, 10000 ); camera.position.z = 1000; scene = new THREE.Scene(); geometry = new THREE.CubeGeometry( 200, 200, 200 ); material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } ); mesh = new THREE.Mesh( geometry, material ); scene.addObject( mesh ); // create the particle variables var particleCount = 1800, particles = new THREE.Geometry(), pMaterial = new THREE.ParticleBasicMaterial({ color: 0xFFFFFF, size: 20 }); // now create the individual particles for(var p = 0; p < particleCount; p++) { // create a particle with random // position values, -250 -> 250 var pX = Math.random() * 500 - 250, pY = Math.random() * 500 - 250, pZ = Math.random() * 500 - 250, particle = new THREE.Vertex( new THREE.Vector3(pX, pY, pZ) ); // add it to the geometry particles.vertices.push(particle); } // create the particle system var particleSystem = new THREE.ParticleSystem( particles, pMaterial); // add it to the scene scene.addChild(particleSystem); renderer = new THREE.CanvasRenderer(); renderer.setSize( window.innerWidth, window.innerHeight ); document.body.appendChild( renderer.domElement ); } function animate() { // Include examples/js/RequestAnimationFrame.js for cross-browser compatibility. requestAnimationFrame( animate ); render(); } function render() { mesh.rotation.x += 0.01; mesh.rotation.y += 0.02; renderer.render( scene, camera ); } </script> </body></html>
Create a new entry at this position