lines_test.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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">
  21. var SCREEN_WIDTH = window.innerWidth,
  22. SCREEN_HEIGHT = window.innerHeight,
  23. mouseX = 0, mouseY = 0,
  24. windowHalfX = window.innerWidth / 2,
  25. windowHalfY = window.innerHeight / 2,
  26. SEPARATION = 200,
  27. AMOUNTX = 10,
  28. AMOUNTY = 10,
  29. camera, scene, renderer,
  30. stats;
  31. init();
  32. setInterval(loop, 1000 / 60);
  33. function init() {
  34. var container, separation = 100, amountX = 50, amountY = 50,
  35. particles, particle, material;
  36. container = document.createElement('div');
  37. document.body.appendChild(container);
  38. camera = new THREE.Camera( 75, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 10000 );
  39. camera.position.z = 1000;
  40. scene = new THREE.Scene();
  41. renderer = new THREE.CanvasRenderer();
  42. renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
  43. container.appendChild(renderer.domElement);
  44. // particles
  45. material = new THREE.ParticleCircleMaterial( 0xffffff, 1 );
  46. var geometry = new THREE.Geometry();
  47. for (var i = 0; i < 100; i++) {
  48. particle = new THREE.Particle( material );
  49. particle.position.x = Math.random() * 2 - 1;
  50. particle.position.y = Math.random() * 2 - 1;
  51. particle.position.z = Math.random() * 2 - 1;
  52. particle.position.normalize();
  53. particle.position.multiplyScalar(Math.random() * 10 + 450);
  54. particle.scale.x = particle.scale.y = 5;
  55. scene.addObject( particle );
  56. geometry.vertices.push( new THREE.Vertex( particle.position ) );
  57. }
  58. // lines
  59. var line = new THREE.Line( geometry, new THREE.LineColorMaterial( 0xffffff, Math.random(), 1 ) );
  60. scene.addObject(line);
  61. /*
  62. stats = new Stats();
  63. stats.domElement.style.position = 'absolute';
  64. stats.domElement.style.top = '0px';
  65. container.appendChild(stats.domElement);
  66. */
  67. document.addEventListener('mousemove', onDocumentMouseMove, false);
  68. document.addEventListener('touchstart', onDocumentTouchStart, false);
  69. document.addEventListener('touchmove', onDocumentTouchMove, false);
  70. }
  71. //
  72. function onDocumentMouseMove(event) {
  73. mouseX = event.clientX - windowHalfX;
  74. mouseY = event.clientY - windowHalfY;
  75. }
  76. function onDocumentTouchStart( event ) {
  77. if(event.touches.length > 1) {
  78. event.preventDefault();
  79. mouseX = event.touches[0].pageX - windowHalfX;
  80. mouseY = event.touches[0].pageY - windowHalfY;
  81. }
  82. }
  83. function onDocumentTouchMove( event ) {
  84. if(event.touches.length == 1) {
  85. event.preventDefault();
  86. mouseX = event.touches[0].pageX - windowHalfX;
  87. mouseY = event.touches[0].pageY - windowHalfY;
  88. }
  89. }
  90. //
  91. function loop() {
  92. camera.position.x += (mouseX - camera.position.x) * .05;
  93. camera.position.y += (-mouseY + 200 - camera.position.y) * .05;
  94. camera.updateMatrix();
  95. renderer.render(scene, camera);
  96. // stats.update();
  97. }
  98. </script>
  99. </body>
  100. </html>