not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.6 KiB

  1. var canvas = document.querySelector('canvas');
  2. var width = canvas.offsetWidth,
  3. height = canvas.offsetHeight;
  4. var renderer = new THREE.WebGLRenderer({
  5. canvas: canvas,
  6. antialias: true,
  7. alpha: true
  8. });
  9. renderer.setPixelRatio(window.devicePixelRatio > 1 ? 2 : 1);
  10. renderer.setSize(width, height);
  11. renderer.setClearColor(0x000000,0);
  12. var scene = new THREE.Scene();
  13. var camera = new THREE.PerspectiveCamera(40, width / height, 0.1, 1000);
  14. camera.position.set(0, 0, 350);
  15. var sphere = new THREE.Group();
  16. scene.add(sphere);
  17. var material = new THREE.LineBasicMaterial({
  18. color: 0x2169e5
  19. });
  20. var linesAmount = 18;
  21. var radius = 100;
  22. var verticesAmount = 50;
  23. for(var j=0;j<linesAmount;j++){
  24. var index = j;
  25. var geometry = new THREE.Geometry();
  26. geometry.y = (index/linesAmount) * radius*2;
  27. for(var i=0;i<=verticesAmount;i++) {
  28. var vector = new THREE.Vector3();
  29. vector.x = Math.cos(i/verticesAmount * Math.PI*2);
  30. vector.z = Math.sin(i/verticesAmount * Math.PI*2);
  31. vector._o = vector.clone();
  32. geometry.vertices.push(vector);
  33. }
  34. var line = new THREE.Line(geometry, material);
  35. sphere.add(line);
  36. }
  37. function updateVertices (a) {
  38. for(var j=0;j<sphere.children.length;j++){
  39. var line = sphere.children[j];
  40. line.geometry.y += 0.3;
  41. if(line.geometry.y > radius*2) {
  42. line.geometry.y = 0;
  43. }
  44. var radiusHeight = Math.sqrt(line.geometry.y * (2*radius-line.geometry.y));
  45. for(var i=0;i<=verticesAmount;i++) {
  46. var vector = line.geometry.vertices[i];
  47. var ratio = noise.simplex3(vector.x*0.009, vector.z*0.009 + a*0.0006, line.geometry.y*0.009) * 15;
  48. vector.copy(vector._o);
  49. vector.multiplyScalar(radiusHeight + ratio);
  50. vector.y = line.geometry.y - radius;
  51. }
  52. line.geometry.verticesNeedUpdate = true;
  53. }
  54. }
  55. function render(a) {
  56. requestAnimationFrame(render);
  57. updateVertices(a);
  58. renderer.render(scene, camera);
  59. }
  60. function onResize() {
  61. canvas.style.width = '';
  62. canvas.style.height = '';
  63. width = canvas.offsetWidth;
  64. height = canvas.offsetHeight;
  65. camera.aspect = width / height;
  66. camera.updateProjectionMatrix();
  67. renderer.setSize(width, height);
  68. }
  69. var mouse = new THREE.Vector2(0.8, 0.5);
  70. function onMouseMove(e) {
  71. mouse.y = e.clientY / window.innerHeight;
  72. TweenMax.to(sphere.rotation, 2, {
  73. x : (mouse.y * 1),
  74. ease:Power1.easeOut
  75. });
  76. }
  77. requestAnimationFrame(render);
  78. window.addEventListener("mousemove", onMouseMove);
  79. var resizeTm;
  80. window.addEventListener("resize", function(){
  81. resizeTm = clearTimeout(resizeTm);
  82. resizeTm = setTimeout(onResize, 200);
  83. });