particles_floor.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <title>three.js - 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/Stats.js"></script>
  21. <script type="text/javascript">
  22. var SCREEN_WIDTH = window.innerWidth;
  23. var SCREEN_HEIGHT = window.innerHeight;
  24. var SEPARATION = 100;
  25. var AMOUNTX = 50;
  26. var AMOUNTY = 50;
  27. var container;
  28. var stats;
  29. var particle;
  30. var camera;
  31. var scene;
  32. var renderer;
  33. var mouseX = 0;
  34. var mouseY = 0;
  35. var windowHalfX = window.innerWidth / 2;
  36. var windowHalfY = window.innerHeight / 2;
  37. init();
  38. setInterval(loop, 1000 / 60);
  39. function init() {
  40. container = document.createElement('div');
  41. document.body.appendChild(container);
  42. camera = new THREE.Camera( 75, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 10000 );
  43. camera.position.z = 1000;
  44. scene = new THREE.Scene();
  45. renderer = new THREE.CanvasRenderer();
  46. renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
  47. var material = new THREE.ParticleCircleMaterial(0xffffff, 1);
  48. for (var ix = 0; ix < AMOUNTX; ix++) {
  49. for(var iy = 0; iy < AMOUNTY; iy++) {
  50. particle = new THREE.Particle( material );
  51. particle.position.x = ix * SEPARATION - ((AMOUNTX * SEPARATION) / 2);
  52. particle.position.z = iy * SEPARATION - ((AMOUNTY * SEPARATION) / 2);
  53. scene.add( particle );
  54. }
  55. }
  56. container.appendChild(renderer.domElement);
  57. stats = new Stats();
  58. stats.domElement.style.position = 'absolute';
  59. stats.domElement.style.top = '0px';
  60. container.appendChild(stats.domElement);
  61. document.addEventListener('mousemove', onDocumentMouseMove, false);
  62. document.addEventListener('touchstart', onDocumentTouchStart, false);
  63. document.addEventListener('touchmove', onDocumentTouchMove, false);
  64. }
  65. //
  66. function onDocumentMouseMove(event) {
  67. mouseX = event.clientX - windowHalfX;
  68. mouseY = event.clientY - windowHalfY;
  69. }
  70. function onDocumentTouchStart( event ) {
  71. if(event.touches.length > 1) {
  72. event.preventDefault();
  73. mouseX = event.touches[0].pageX - windowHalfX;
  74. mouseY = event.touches[0].pageY - windowHalfY;
  75. }
  76. }
  77. function onDocumentTouchMove( event ) {
  78. if(event.touches.length == 1) {
  79. event.preventDefault();
  80. mouseX = event.touches[0].pageX - windowHalfX;
  81. mouseY = event.touches[0].pageY - windowHalfY;
  82. }
  83. }
  84. //
  85. function loop() {
  86. camera.position.x += (mouseX - camera.position.x) * .05;
  87. camera.position.y += (-mouseY - camera.position.y) * .05;
  88. renderer.render(scene, camera);
  89. stats.update();
  90. }
  91. </script>
  92. </body>
  93. </html>