canvas_particles_floor.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <title>three.js canvas - particles - floor</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
  7. <style type="text/css">
  8. body {
  9. background-color: #000000;
  10. margin: 0px;
  11. overflow: hidden;
  12. }
  13. a {
  14. color:#0078ff;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <script type="text/javascript" src="../build/Three.js"></script>
  20. <script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
  21. <script type="text/javascript" src="js/Stats.js"></script>
  22. <script type="text/javascript">
  23. var SEPARATION = 100;
  24. var AMOUNTX = 50;
  25. var AMOUNTY = 50;
  26. var container, stats;
  27. var camera, scene, renderer, particle;
  28. var mouseX = 0, mouseY = 0;
  29. var windowHalfX = window.innerWidth / 2;
  30. var windowHalfY = window.innerHeight / 2;
  31. init();
  32. animate();
  33. function init() {
  34. container = document.createElement( 'div' );
  35. document.body.appendChild( container );
  36. camera = new THREE.Camera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
  37. camera.position.z = 1000;
  38. scene = new THREE.Scene();
  39. var material = new THREE.ParticleCircleMaterial( { color: 0xffffff, opacity: 1 } );
  40. for ( var ix = 0; ix < AMOUNTX; ix++ ) {
  41. for ( var iy = 0; iy < AMOUNTY; iy++ ) {
  42. particle = new THREE.Particle( material );
  43. particle.position.x = ix * SEPARATION - ( ( AMOUNTX * SEPARATION ) / 2 );
  44. particle.position.z = iy * SEPARATION - ( ( AMOUNTY * SEPARATION ) / 2 );
  45. scene.addObject( particle );
  46. }
  47. }
  48. renderer = new THREE.CanvasRenderer();
  49. renderer.setSize( window.innerWidth, window.innerHeight );
  50. container.appendChild( renderer.domElement );
  51. stats = new Stats();
  52. stats.domElement.style.position = 'absolute';
  53. stats.domElement.style.top = '0px';
  54. container.appendChild( stats.domElement );
  55. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  56. document.addEventListener( 'touchstart', onDocumentTouchStart, false );
  57. document.addEventListener( 'touchmove', onDocumentTouchMove, false );
  58. }
  59. //
  60. function onDocumentMouseMove(event) {
  61. mouseX = event.clientX - windowHalfX;
  62. mouseY = event.clientY - windowHalfY;
  63. }
  64. function onDocumentTouchStart( event ) {
  65. if ( event.touches.length > 1 ) {
  66. event.preventDefault();
  67. mouseX = event.touches[ 0 ].pageX - windowHalfX;
  68. mouseY = event.touches[ 0 ].pageY - windowHalfY;
  69. }
  70. }
  71. function onDocumentTouchMove( event ) {
  72. if ( event.touches.length == 1 ) {
  73. event.preventDefault();
  74. mouseX = event.touches[ 0 ].pageX - windowHalfX;
  75. mouseY = event.touches[ 0 ].pageY - windowHalfY;
  76. }
  77. }
  78. //
  79. function animate() {
  80. requestAnimationFrame( animate );
  81. render();
  82. stats.update();
  83. }
  84. function render() {
  85. camera.position.x += ( mouseX - camera.position.x ) * .05;
  86. camera.position.y += ( - mouseY - camera.position.y ) * .05;
  87. renderer.render( scene, camera );
  88. }
  89. </script>
  90. </body>
  91. </html>