lines_sphere.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. for (var i = 0; i < 1000; i++) {
  47. particle = new THREE.Particle( material );
  48. particle.position.x = Math.random() * 2 - 1;
  49. particle.position.y = Math.random() * 2 - 1;
  50. particle.position.z = Math.random() * 2 - 1;
  51. particle.position.normalize();
  52. particle.position.multiplyScalar(Math.random() * 10 + 450);
  53. scene.addObject( particle );
  54. }
  55. // lines
  56. for (var i = 0; i < 300; i++) {
  57. var geometry = new THREE.Geometry();
  58. var vector = new THREE.Vector3( Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1 );
  59. vector.normalize();
  60. vector.multiplyScalar(450);
  61. geometry.vertices.push(new THREE.Vertex(vector));
  62. var vector2 = vector.clone();
  63. vector2.multiplyScalar(Math.random() * 0.3 + 1);
  64. geometry.vertices.push(new THREE.Vertex(vector2));
  65. var line = new THREE.Line( geometry, new THREE.LineColorMaterial( 0xffffff, Math.random() ) );
  66. scene.addObject(line);
  67. }
  68. /*
  69. stats = new Stats();
  70. stats.domElement.style.position = 'absolute';
  71. stats.domElement.style.top = '0px';
  72. container.appendChild(stats.domElement);
  73. */
  74. document.addEventListener('mousemove', onDocumentMouseMove, false);
  75. document.addEventListener('touchstart', onDocumentTouchStart, false);
  76. document.addEventListener('touchmove', onDocumentTouchMove, false);
  77. }
  78. //
  79. function onDocumentMouseMove(event) {
  80. mouseX = event.clientX - windowHalfX;
  81. mouseY = event.clientY - windowHalfY;
  82. }
  83. function onDocumentTouchStart( 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. function onDocumentTouchMove( event ) {
  91. if(event.touches.length == 1) {
  92. event.preventDefault();
  93. mouseX = event.touches[0].pageX - windowHalfX;
  94. mouseY = event.touches[0].pageY - windowHalfY;
  95. }
  96. }
  97. //
  98. function loop() {
  99. camera.position.x += (mouseX - camera.position.x) * .05;
  100. camera.position.y += (-mouseY + 200 - camera.position.y) * .05;
  101. camera.updateMatrix();
  102. renderer.render(scene, camera);
  103. // stats.update();
  104. }
  105. </script>
  106. </body>
  107. </html>