canvas-nest.min.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // JavaScript Document
  2. ! function() {
  3. function o(w, v, i) {
  4. return w.getAttribute(v) || i
  5. }
  6. function j(i) {
  7. return document.getElementsByTagName(i)
  8. }
  9. function l() {
  10. var i = j("script"),
  11. w = i.length,
  12. v = i[w - 1];
  13. return {
  14. l: w,
  15. z: o(v, "zIndex", -2),
  16. o: o(v, "opacity", 0.8),
  17. c: o(v, "color", "255,255,255"),
  18. n: o(v, "count", 240)
  19. }
  20. }
  21. function k() {
  22. r = u.width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth, n = u.height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
  23. }
  24. function b() {
  25. delay = delay + 1;
  26. if( delay < 5 ) { m(b) } else { delay = 0;
  27. e.clearRect(0, 0, r, n);
  28. var w = [f].concat(t);
  29. var x, v, A, B, z, y;
  30. t.forEach(function(i) {
  31. i.x += i.xa, i.y += i.ya, i.xa *= i.x > r || i.x < 0 ? -1 : 1, i.ya *= i.y > n || i.y < 0 ? -1 : 1, e.fillRect(i.x - 0.5, i.y - 0.5, 2, 2);e.fillStyle="#FFFFFF";
  32. for (v = 0; v < w.length; v++) {
  33. x = w[v];
  34. if (i !== x && null !== x.x && null !== x.y) {
  35. B = i.x - x.x, z = i.y - x.y, y = B * B + z * z;
  36. y < x.max && (x === f && y >= x.max / 2 && (i.x -= 0.03 * B, i.y -= 0.03 * z), A = (x.max - y) / x.max, e.beginPath(), e.lineWidth = A / 2, e.strokeStyle = "rgba(" + s.c + "," + (A + 0.2) + ")", e.moveTo(i.x, i.y), e.lineTo(x.x, x.y), e.stroke())
  37. }
  38. }
  39. w.splice(w.indexOf(i), 1)
  40. }), m(b) }
  41. }
  42. var u = document.createElement("canvas"),
  43. s = l(),
  44. c = "c_n" + s.l,
  45. e = u.getContext("2d"),
  46. delay = 0,
  47. r, n, m = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(i) {
  48. window.setTimeout(i, 1000 / 45)
  49. },
  50. a = Math.random,
  51. f = {
  52. x: null,
  53. y: null,
  54. max: 20000
  55. }
  56. u.id = c;
  57. u.style.cssText = "position:fixed;top:0;left:0;z-index:" + s.z + ";opacity:" + s.o;
  58. j("body")[0].appendChild(u);
  59. k(), window.onresize = k;
  60. window.onmousemove = function(i) {
  61. i = i || window.event, f.x = i.clientX, f.y = i.clientY
  62. }, window.onmouseout = function() {
  63. f.x = null, f.y = null
  64. };
  65. for (var t = [], p = 0; s.n > p; p++) {
  66. var h = a() * r,
  67. g = a() * n,
  68. q = 2 * a() - 1,
  69. d = 2 * a() - 1;
  70. t.push({
  71. x: h,
  72. y: g,
  73. xa: q,
  74. ya: d,
  75. max: 6000
  76. })
  77. }
  78. setTimeout(function() {
  79. b()
  80. }, 100)
  81. }();