floor.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. {
  10. background-color: #000000;
  11. margin: 0px;
  12. overflow: hidden;
  13. }
  14. a
  15. {
  16. color:#0078ff;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <script type="text/javascript" src="http://github.com/mrdoob/three.js/raw/master/build/three.js"></script>
  22. <script type="text/javascript" src="http://github.com/mrdoob/stats.js/raw/master/build/stats.js"></script>
  23. <script type="text/javascript">
  24. var SCREEN_WIDTH = window.innerWidth;
  25. var SCREEN_HEIGHT = window.innerHeight;
  26. var SEPARATION = 100;
  27. var AMOUNTX = 50;
  28. var AMOUNTY = 50;
  29. var container;
  30. var stats;
  31. var particle;
  32. var camera;
  33. var scene;
  34. var renderer;
  35. var mouseX = 0;
  36. var mouseY = 0;
  37. var windowHalfX = window.innerWidth >> 1;
  38. var windowHalfY = window.innerHeight >> 1;
  39. document.addEventListener('mousemove', onDocumentMouseMove, false);
  40. document.addEventListener('touchstart', onDocumentTouchStart, false);
  41. init();
  42. setInterval(loop, 1000 / 60);
  43. function init()
  44. {
  45. container = document.createElement('div');
  46. document.body.appendChild(container);
  47. camera = new Camera(0, 0, 1000);
  48. camera.focus = 200;
  49. scene = new Scene();
  50. renderer = new CanvasRenderer();
  51. renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
  52. particles = new Array();
  53. var material = new ColorMaterial(0xffffff, 1);
  54. for (var ix = 0; ix < AMOUNTX; ix++)
  55. {
  56. for(var iy = 0; iy < AMOUNTY; iy++)
  57. {
  58. particle = new Particle( material );
  59. particle.position.x = ix * SEPARATION - ((AMOUNTX * SEPARATION) / 2);
  60. particle.position.z = iy * SEPARATION - ((AMOUNTY * SEPARATION) / 2);
  61. particle.updateMatrix();
  62. scene.add( particle );
  63. }
  64. }
  65. container.appendChild(renderer.viewport);
  66. stats = new Stats();
  67. container.appendChild( stats.getDisplayElement() );
  68. }
  69. //
  70. function onDocumentMouseMove(event)
  71. {
  72. mouseX = event.clientX - windowHalfX;
  73. mouseY = event.clientY - windowHalfY;
  74. }
  75. function onDocumentTouchStart( event )
  76. {
  77. if(event.touches.length == 1)
  78. {
  79. event.preventDefault();
  80. mouseX = event.touches[0].pageX - windowHalfX;
  81. mouseY = event.touches[0].pageY - windowHalfY;
  82. document.addEventListener('touchmove', onDocumentTouchMove, false);
  83. document.addEventListener('touchend', onDocumentTouchEnd, false);
  84. }
  85. }
  86. function onDocumentTouchMove( event )
  87. {
  88. if(event.touches.length == 1)
  89. {
  90. event.preventDefault();
  91. mouseX = event.touches[0].pageX - windowHalfX;
  92. mouseY = event.touches[0].pageY - windowHalfY;
  93. }
  94. }
  95. function onDocumentTouchEnd( event )
  96. {
  97. if(event.touches.length == 0)
  98. {
  99. event.preventDefault();
  100. mouseX = event.touches[0].pageX - windowHalfX;
  101. mouseY = event.touches[0].pageY - windowHalfY;
  102. document.removeEventListener('touchmove', onDocumentTouchMove, false);
  103. document.removeEventListener('touchend', onDocumentTouchEnd, false);
  104. }
  105. }
  106. //
  107. function loop()
  108. {
  109. camera.x += (mouseX - camera.x) * .05;
  110. camera.y += (-mouseY - camera.y) * .05;
  111. camera.updateMatrix();
  112. renderer.render(scene, camera);
  113. stats.update();
  114. }
  115. </script>
  116. </body>
  117. </html>