Advertisement
Guest User

Updated factor_min.js

a guest
Nov 1st, 2012
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function n() {
  2.     function a(a, c) {
  3.         return "undefined" !== typeof a ? a : c
  4.     }
  5.     this.d = function () {
  6.         return (new Date).getTime()
  7.     };
  8.     this.getTime = function () {
  9.         var a = this.d() - this.e,
  10.             a = this.b + this.speed(a),
  11.             a = Math.min(a, this.g);
  12.         return a = Math.max(a, this.h)
  13.     };
  14.     this.a = function (a) {
  15.         this.b = this.getTime();
  16.         this.e = this.d();
  17.         this.speed = "function" === typeof a ? a : function (c) {
  18.             return c * a
  19.         }
  20.     };
  21.     this.c = function () {
  22.         return (this.speed(1E3) - this.speed(0)) / 1E3
  23.     };
  24.     this.f = function () {
  25.         var a = this.speed;
  26.         this.a(function (c) {
  27.             return 4 * a(c)
  28.         })
  29.     };
  30.     this.stop = function () {
  31.         this.a(0)
  32.     };
  33.     this.i = function (a) {
  34.         this.b += a
  35.     };
  36.     this.h = a(0, 0);
  37.     this.g = a(9999500, 1E100);
  38.     this.b = a(0, 0);
  39.     this.e = this.d();
  40.     this.speed = function (a) {
  41.         return a
  42.     };
  43.     this.a(a(0, 1))
  44. };
  45. window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || window.oRequestAnimationFrame;
  46. window.requestAnimationFrame || (window.requestAnimationFrame = function (a) {
  47.     var b = 0,
  48.         c = Math.max(0, 16 - b);
  49.     return window.setTimeout(function () {
  50.         var c = (new Date).getTime();
  51.         a(c);
  52.         b = (new Date).getTime() - c
  53.     }, c)
  54. });
  55. var p, t, u, v, x, y, z;
  56. var lastPointX = 0;
  57. var lastPointY = 0;
  58. var first = 1;
  59.  
  60. function A(a, b, c) {
  61.     var d = document.getElementById(a),
  62.         i = document.createElement("canvas");
  63.     i.setAttribute("width", 30);
  64.     i.setAttribute("height", 30);
  65.     d.appendChild(i);
  66.     d.onclick = function () {
  67.         B();
  68.         document.getElementById(a).className = "on";
  69.         b()
  70.     };
  71.     d.onmouseover = function () {
  72.         this.style.border = "solid 1px rgba(0,0,0,0.1)"
  73.     };
  74.     d.onmouseout = function () {
  75.         this.style.border = ""
  76.     };
  77.     c(i);
  78.     return d
  79. }
  80. function B() {
  81.     for (var a = document.getElementById("controls").childNodes, b = 0; b < a.length; b++) a[b].className = "off"
  82. }
  83.  
  84. function F(a, b, c, d) {
  85.     var d = b + 0.85 * c * d,
  86.         i = 0.5 - c / 2,
  87.         c = 0.5 + c / 2,
  88.         h = a.getContext("2d");
  89.     h.save();
  90.     h.scale(a.width, a.height);
  91.     h.beginPath();
  92.     h.moveTo(b, i);
  93.     h.lineTo(d, 0.5);
  94.     h.lineTo(b, c);
  95.     h.closePath();
  96.     h.lineJoin = "round";
  97.     h.fillStyle = "#fff";
  98.     h.fill();
  99.     h.lineWidth = 1 / a.width;
  100.     h.strokeStyle = "rgba(0,0,0,0.2)";
  101.     h.stroke();
  102.     h.restore()
  103. }
  104. function G(a) {
  105.     F(a, 0.44, 0.4, - 1);
  106.     F(a, 0.8, 0.4, - 1)
  107. }
  108. function H(a) {
  109.     F(a, 0.56, 0.4, 1);
  110.     F(a, 0.2, 0.4, 1)
  111. }
  112. function I(a) {
  113.     F(a, 0.7, 0.6, - 1)
  114. }
  115. function J(a) {
  116.     F(a, 0.3, 0.6, 1)
  117. }
  118.  
  119. function K(a) {
  120.     var b = a.getContext("2d");
  121.     b.save();
  122.     b.scale(a.width, a.height);
  123.     b.beginPath();
  124.     b.rect(0.25, 0.25, 0.5, 0.5);
  125.     b.lineJoin = "round";
  126.     b.fillStyle = "#fff";
  127.     b.fill();
  128.     b.lineWidth = 1 / a.width;
  129.     b.strokeStyle = "rgba(0,0,0,0.2)";
  130.     b.stroke();
  131.     b.restore()
  132. }
  133. function L(a, b) {
  134.     var c = a * v,
  135.         d = b * v;
  136.     return Math.acos(Math.cos(c) * Math.cos(d) + Math.sin(c) * Math.sin(d)) / v
  137. }
  138.  
  139. function M(a, b, c, d, i, h, q, r, k) {
  140.     if (i >= d.length) a.push(h), b.push(q), c.push(r);
  141.     else {
  142.         var e = d[i],
  143.             m = i + 1 < d.length ? d[i + 1] : 0,
  144.             l = 0.4 * r * v / (e + 3.4);
  145.         m && (l *= 0.93, 2 === m && (l *= 1.2), 3 === m && 7 >= e && (l *= 1.12), 4 === m && 7 >= e && (l *= 1.08));
  146.         var r = r - l,
  147.             j;
  148.         j = k + (4 === e ? -t : -u);
  149.         for (var s = v / e, f = 0; f < e; f++) {
  150.             var g = j + f * s;
  151.             M(a, b, c, d, i + 1, h + r * Math.cos(g), q + r * Math.sin(g), l, 2 === m ? g - u : k)
  152.         }
  153.     }
  154. }
  155. function N(a) {
  156.     if (1 >= a) return [];
  157.     var b = O(a),
  158.         a = N(a / b);
  159.     a.push(b);
  160.     return a
  161. }
  162.  
  163. function O(a) {
  164.     if (0 === a % 4) return 4;
  165.     if (0 === a % 2) return 2;
  166.     for (var b = Math.sqrt(a) + 1 | 0, c = 3; c <= b; c += 2) if (0 === a % c) return c;
  167.     return a
  168. }
  169. function P(a, b) {
  170.     var c;
  171.     if (1 > b.length) c = "";
  172.     else if (1 >= b.length && 4 !== b[0]) c = "prime";
  173.     else {
  174.         c = "";
  175.         for (var d = 0; d < b.length; d++) {
  176.             "" !== c && (c += '<span class="times">&times;</span>');
  177.             var i = b[d];
  178.             c = 4 == i ? c + '2<span class="times">&times;</span>2' : c + i
  179.         }
  180.     }
  181.     return '<span class="number">' + a + '</span><br><span class="decomposition">' + c + "</span>"
  182. }
  183. function Q() {
  184.     var a, b = 0,
  185.         c = a = 0,
  186.         d = 0;
  187.     try {
  188.         b = window.innerWidth
  189.     } catch (i) {}
  190.     try {
  191.         a = window.innerHeight
  192.     } catch (h) {}
  193.     try {
  194.         c = screen.availWidth
  195.     } catch (q) {}
  196.     try {
  197.         d = screen.availHeight
  198.     } catch (r) {}
  199.     d && (d -= 70);
  200.     b = b ? b : c;
  201.     a = a ? a : d;
  202.     b || (b = 974);
  203.     a || (a = 718);
  204.     a = Math.min(b, a);
  205.     a = Math.max(a, 350);
  206.     var k = Math.round(0.45 * (a - 90)),
  207.         k = Math.max(k, 50),
  208.         k = Math.min(k, 600),
  209.         e = 2 * k + 1;
  210.     if (e != canvas.width || e != canvas.height) canvas.width = e, canvas.height = e, a = Math.round(-e / 2) + "px", canvas.style.marginLeft = a, canvas.style.marginTop = a;
  211.     var m = e / 2,
  212.         l = e / 2;
  213.     a = y.getTime() + 700;
  214.     var j;
  215.     j = Math.max(a / 1E3 | 0, 1);
  216.     var s = j + 1,
  217.         f = a - 500 - 1E3 * j,
  218.         f = 3 * (f / 1E3),
  219.         f = Math.max(f, 0),
  220.         f = Math.min(f, 1),
  221.         f = 0.5 - 0.5 * Math.cos(f * x),
  222.         g = N(j);
  223.     a = [];
  224.     d = [];
  225.     b = [];
  226.     M(a, d, b, g, 0, m, l, k * (1 - 0.6 / (j + 1)), 0);
  227.     var w = N(s),
  228.         c = [],
  229.         C = [],
  230.         D = [];
  231.     M(c, C, D, w, 0, m, l, k * (1 - 0.6 / (s + 1)), 0);
  232.     k = document.getElementById("status1");
  233.     m = document.getElementById("status2");
  234.     k.innerHTML = P(j, g);
  235.     m.innerHTML = P(s, w);
  236.     j = 0.7 / (1 - f + f * f);
  237.     k.style.opacity = 0.001 > j * (1 - f) ? 0.001 : 0.999 < j * (1 - f) ? 0.999 : j * (1 - f);
  238.     m.style.opacity = 0.001 > j * f ? 0.001 : 0.999 < j * f ? 0.999 : j * f;
  239.    
  240.     //p.clearRect(0, 0, e, e);
  241.        
  242.     e = f;
  243.     j = a.length;
  244.     g = c.length;
  245.     s = 1 / j;
  246.     f = 1 / g;
  247.     k = 1 - e;
  248.     for (g -= 1; 0 <= g; g--) {
  249.     if(g==0){
  250.         var E;
  251.         g < j ? (w = k * b[g] + e * D[g], m = k * g * s + e * g * f, l = k * a[g] + e * c[g], E = k * d[g] + e * C[g]) : (w = e * D[g], m = g * f, l = k * a[j - 1] + e * c[g], E = k * d[j - 1] + e * C[g]);
  252.         p.fillStyle = z[m * z.length | 0];
  253.         p.strokeStyle = p.fillStyle;
  254.         if(first==1){
  255.             first=0;
  256.         }
  257.         else{
  258.             p.beginPath();
  259.             p.moveTo(lastPointX,lastPointY);
  260.             p.lineTo(l,E);
  261.             p.closePath();
  262.             p.stroke();
  263.         }
  264.             lastPointX = l;
  265.             lastPointY = E;
  266.         }
  267.     }
  268.     window.requestAnimationFrame(Q)
  269. }
  270. window.start = function () {
  271.     canvas = document.getElementById("canvas");
  272.     if (!canvas.getContext || !canvas.getContext("2d")) {
  273.         var a = document.getElementById("frame"),
  274.             b = document.createElement("div");
  275.         b.setAttribute("id", "error");
  276.         b.innerHTML = 'To view this visualization, upgrade to a modern web browser like <a href="http://www.google.com/chrome/">Chrome</a>.';
  277.         a.appendChild(b)
  278.     } else {
  279.         p = canvas.getContext("2d");
  280.         t = Math.PI / 4;
  281.         u = Math.PI / 2;
  282.         v = 2 * Math.PI;
  283.         x = Math.PI;
  284.         y = new n;
  285.         for (var a = 1E3, b = [], c = 0, a = 1E3; c < a; c++) {
  286.             var d = c / a + 0.9,
  287.                 i = 766.5 * Math.max(1 / 3 - L(1 / 6, d), 0),
  288.                 h = 766.5 * Math.max(1 / 3 - L(0.5, d), 0),
  289.                 d = 766.5 * Math.max(1 / 3 - L(5 / 6, d), 0),
  290.                 q = Math.sqrt(4E4 / (2 * i * i + 3 * h * h + d * d)),
  291.                 i = Math.round(i * q),
  292.                 h = Math.round(h * q),
  293.                 d = Math.round(d * q);
  294.             b[c] = "rgb(" + i + "," + h + "," + d + ")"
  295.         }
  296.         z = b;
  297.         A("fast_backward", function () {
  298.             -2 < y.c() ? y.a(-4) : -100 < y.c() && y.f()
  299.         }, G);
  300.         A("play_backward", function () {
  301.             y.a(-1)
  302.         }, I);
  303.         A("stop", function () {
  304.             y.a(0)
  305.         }, K);
  306.         a = A("play_forward", function () {
  307.             y.a(1)
  308.         }, J);
  309.         A("fast_forward", function () {
  310.             2 > y.c() ? y.a(4) : 100 > y.c() && y.f()
  311.         }, H);
  312.         B();
  313.         a.onclick();
  314.         window.requestAnimationFrame(Q)
  315.     }
  316. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement