quietflow.min.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /**
  2. * quietflow.min.js
  3. * Paul Krishnamurthy 2016
  4. *
  5. * https://paulkr.com
  6. * paul@paulkr.com
  7. */
  8. function randCol(a, o, e, r) {
  9. return "rgba(" + Math.floor(Math.random() * a).toString() + "," + Math.floor(Math.random() * o).toString() + "," + Math.floor(Math.random() * e).toString() + "," + r + ")"
  10. }
  11. $.fn.quietflow = function (a) {
  12. function o(a) {
  13. void 0 !== x.speed ? setTimeout(function () {
  14. w = requestAnimationFrame(a)
  15. }, x.speed) : w = requestAnimationFrame(a)
  16. }
  17. function e() {
  18. for (var a = 0; h > a; a += x.squareSize + 1) for (var r = 0; c > r; r += x.squareSize + 1) S.fillStyle = randCol(x.maxRed, x.maxGreen, x.maxBlue, 1), S.fillRect(a, r, x.squareSize, x.squareSize);
  19. o(e)
  20. }
  21. function r() {
  22. (B + y > h || 0 > B + y) && (y = -y), (F + k > c || 0 > F + k) && (k = -k), B += y, F += k, S.fillStyle = x.backgroundCol, S.fillRect(0, 0, h, c);
  23. for (var a = 0; a < x.miniRadii; a++) for (var e = 0; e < x.miniRadii; e++) {
  24. var t = a / x.miniRadii * h, l = e / x.miniRadii * c,
  25. i = Math.sqrt(Math.pow(B - t, 2) + Math.pow(F - l, 2)) / x.mainRadius;
  26. S.beginPath(), S.fillStyle = x.circleCol, S.arc(t, l, i, 0, 2 * Math.PI, !0), S.closePath(), S.fill()
  27. }
  28. o(r)
  29. }
  30. function t() {
  31. S.fillStyle = x.backgroundCol, S.fillRect(0, 0, h, c);
  32. for (var a = 0; a < x.bounceBallCount; a++) {
  33. var e = circleData[a], r = 0, l = 1, i = 2, n = 3, s = 4, d = 5;
  34. (e[r] + e[n] > h || e[r] + e[n] < 0) && (e[3] = -e[3]), (e[l] + e[s] > c || e[l] + e[s] < 0) && (e[s] = -e[s]), e[r] += e[n], e[l] += e[s], S.beginPath(), S.fillStyle = e[d], S.arc(e[r], e[l], e[i], 0, 2 * Math.PI, !0), S.closePath(), S.fill()
  35. }
  36. o(t)
  37. }
  38. function l() {
  39. S.fillStyle = x.backgroundCol, S.fillRect(0, 0, h, c), S.beginPath(), S.fillStyle = x.lineColor, S.arc(f, m, 2, 0, 2 * Math.PI, !0), S.closePath(), S.fill();
  40. for (var a = 0; a < x.lines; a++) S.beginPath(), S.moveTo(f, m), S.lineTo(Math.random() * h, Math.random() * c), S.strokeStyle = x.lineColor, S.shadowColor = x.lineGlow, S.shadowBlur = 20, S.stroke();
  41. o(l)
  42. }
  43. function i() {
  44. var a = S.createLinearGradient(0, 0, h / 2, c);
  45. a.addColorStop(0, "#333333"), a.addColorStop(1, "#000"), S.fillStyle = a, S.fillRect(0, 0, h, c);
  46. for (var e = 0; e < P.length; e++) {
  47. var r = P[e], t = 0, l = 1, n = 2, s = 3;
  48. r[t] += r[s], S.beginPath(), S.fillStyle = x.starColor, S.arc(r[t], r[l], r[n], 0, 2 * Math.PI, !0), S.shadowColor = "#FFF", S.shadowBlur = 20, S.closePath(), S.fill(), r[t] > h && (P.splice(e, 1), P.unshift([Math.random() * h / 4 - h / 4, Math.random() * c, Math.random() * x.starSize, Math.ceil(5 * Math.random())]))
  49. }
  50. o(i)
  51. }
  52. function n() {
  53. S.beginPath();
  54. for (var a = [[0, 0], [h, 0], [0, c], [h, c]], e = 0; 4 > e; e++) {
  55. var r = Math.floor(Math.random() * x.specificColors.length);
  56. S.strokeStyle = x.specificColors.length > 0 ? x.specificColors[r] : randCol(255, 255, 255), S.moveTo(a[e][0], a[e][1]), S.lineTo(Math.random() * h, Math.random() * c)
  57. }
  58. S.shadowColor = x.lineGlow, S.shadowBlur = 20, S.stroke(), o(n)
  59. }
  60. function s() {
  61. S.fillStyle = x.backgroundCol, S.fillRect(0, 0, h, c);
  62. for (var a = 0; a < q.length; a++) {
  63. var e = q[a], r = 0, t = 1, l = 2, i = 3, n = 4;
  64. S.fillStyle = e[i], S.fillRect(e[r], e[t], e[l], e[l]), e[r] += e[n], e[t] -= e[n], (e[r] > h + x.maxBoxSize || e[t] < -x.maxBoxSize) && (q.splice(a, 1), 0 == x.specificColors.length ? q.push([Math.random() * h * 2 - h, Math.random() * c * 2 + c, Math.random() * x.maxBoxSize + 1, randCol(255, 255, 255, x.transparent ? .5 : 1), 5 * Math.random()]) : q.push([Math.random() * h * 2 - h, Math.random() * c * 2 + c, Math.random() * x.maxBoxSize + 1, x.specificColors[Math.floor(Math.random() * x.specificColors.length)], 5 * Math.random()]))
  65. }
  66. o(s)
  67. }
  68. var d = $(this), h = d.width(), c = d.height(), f = h / 2, m = c / 2;
  69. $("#Quietflow").remove();
  70. var u = "starfield", M = -1e3,
  71. p = ["squareFlash", "vortex", "bouncingBalls", "shootingLines", "simpleGradient", "starfield", "layeredTriangles", "cornerSpikes", "floatingBoxes"],
  72. C = {
  73. squareFlash: {squareSize: 10, maxRed: 255, maxGreen: 255, maxBlue: 255, speed: 100},
  74. vortex: {mainRadius: 20, miniRadii: 30, backgroundCol: "#3498DB", circleCol: "#34495E", speed: 10},
  75. bouncingBalls: {
  76. specificColors: [],
  77. backgroundCol: "#ECF0F1",
  78. maxRadius: 40,
  79. bounceSpeed: 50,
  80. bounceBallCount: 50,
  81. transparent: !0
  82. },
  83. shootingLines: {backgroundCol: "#000", lineColor: "#FFF", speed: 150, lineGlow: "#FFF", lines: 50},
  84. simpleGradient: {primary: "#D4145A", accent: "#FBB03B"},
  85. starfield: {starColor: "#FFF", starSize: 3, speed: 100},
  86. layeredTriangles: {backgroundCol: "#D6D6D6", transparent: !0, specificColors: [], triangles: 50},
  87. cornerSpikes: {specificColors: [], backgroundCol: "#FFF", lineColor: "#000", speed: 100, lineGlow: "#FFF"},
  88. floatingBoxes: {
  89. specificColors: [],
  90. boxCount: 400,
  91. maxBoxSize: 80,
  92. backgroundCol: "#D6D6D6",
  93. transparent: !1,
  94. speed: 100
  95. }
  96. }, g = document.createElement("canvas"), S = g.getContext("2d");
  97. g.id = "Quietflow", g.width = h, g.height = c, g.style.zIndex = M, g.style.position = "absolute", g.style.top = 0;
  98. var b = d.attr("id");
  99. if (void 0 != b) {
  100. var v = document.getElementById(b);
  101. v.appendChild(g)
  102. } else document.body.appendChild(g);
  103. $.inArray(a.theme, p) > -1 && (u = a.theme);
  104. var x = {};
  105. x = $.extend(C[u], a), $(window).resize(function () {
  106. h = d.width(), c = d.height();
  107. var a = $("#Quietflow").css("width").replace("px", ""), o = $("#Quietflow").css("height").replace("px", "");
  108. $("#Quietflow").css({width: window.innerWidth, height: window.innerHeight});
  109. var e = a / window.innerWidth, r = o / window.innerHeight;
  110. S.scale(e, r)
  111. });
  112. var w;
  113. switch (u) {
  114. case"squareFlash":
  115. e();
  116. break;
  117. case"vortex":
  118. var y = 2, k = 4, B = h / 2, F = c / 2;
  119. r();
  120. break;
  121. case"bouncingBalls":
  122. circleData = [];
  123. for (var R = 0; R < x.bounceBallCount; R++) 0 == x.specificColors.length ? circleData.push([Math.random() * h, Math.random() * c, Math.random() * x.maxRadius, 2 * Math.random(), 4 * Math.random(), randCol(255, 255, 255, x.transparent ? .5 : 1)]) : circleData.push([Math.random() * h, Math.random() * c, Math.random() * x.maxRadius, 2 * Math.random(), 4 * Math.random(), x.specificColors[Math.floor(Math.random() * x.specificColors.length)]]);
  124. t();
  125. break;
  126. case"shootingLines":
  127. l();
  128. break;
  129. case"simpleGradient":
  130. var z = S.createLinearGradient(0, 0, h / 2, c);
  131. z.addColorStop(0, x.primary), z.addColorStop(1, x.accent), S.fillStyle = z, S.fillRect(0, 0, h, c);
  132. break;
  133. case"starfield":
  134. for (var P = [], R = 0; 700 > R; R++) P.push([Math.random() * h * 2 - h, Math.random() * c, Math.random() * x.starSize, Math.ceil(5 * Math.random())]);
  135. i();
  136. break;
  137. case"layeredTriangles":
  138. S.fillStyle = x.backgroundCol, S.fillRect(0, 0, h, c);
  139. for (var R = 0; R < x.triangles; R++) S.beginPath(), S.moveTo(Math.random() * h, Math.random() * c), S.lineTo(Math.random() * h, Math.random() * c), S.lineTo(Math.random() * h, Math.random() * c), x.specificColors.length > 0 ? S.fillStyle = x.specificColors[Math.floor(Math.random() * x.specificColors.length)] : S.fillStyle = randCol(255, 255, 255, .5), S.closePath(), S.fill();
  140. break;
  141. case"cornerSpikes":
  142. S.fillStyle = x.backgroundCol, S.fillRect(0, 0, h, c), n();
  143. break;
  144. case"floatingBoxes":
  145. for (var q = [], R = 0; R < x.boxCount; R++) 0 == x.specificColors.length ? q.push([Math.random() * h * 2 - h, Math.random() * c, Math.random() * x.maxBoxSize + 1, randCol(255, 255, 255, x.transparent ? .5 : 1), 5 * Math.random()]) : q.push([Math.random() * h * 2 - h, Math.random() * c, Math.random() * x.maxBoxSize + 1, x.specificColors[Math.floor(Math.random() * x.specificColors.length)], 5 * Math.random()]);
  146. s()
  147. }
  148. };