// Chrome Experiments #1000 Editor! // Write your own particle behavior and share the code with your URL. // Press Command + E to evaluate your changes. var spacing = 15, size = 10; var center = new THREE.Vector3( 1, 1, 1 ); center.multiplyScalar( Math.floor( size / 2 ) ); return { init: function( particle, i ) { var x = particle.index % size; var y = Math.floor( particle.index / size ) % size; var z = Math.floor( particle.index / ( size * size ) ); particle.position.set( x, y, z ); particle.position.sub( center ); particle.position.multiplyScalar( spacing ); particle.originalPosition = new THREE.Vector3().copy( particle.position ); }, update: function( particle, currentTime ) { var x = particle.index % size; var y = Math.floor( particle.index / size ) % size; var z = Math.floor( particle.index / ( size * size ) ); var scale = Math.max( 0, Math.sin( -currentTime + 0.25 * ( x + y + z ) ) ); particle.position.copy( particle.originalPosition ); particle.position.y += Math.sin( currentTime + x ) * 4; particle.scale.set( scale, scale, scale ); } }