Guest User

Untitled

a guest
Mar 14th, 2010
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var _gaq = _gaq || [];
  2. _gaq.push(["_setAccount", "UA-86951-7"]);
  3. _gaq.push(["_trackPageview"]);
  4. (function () {
  5.     var a = document.createElement("script");
  6.     a.type = "text/javascript";
  7.     a.async = true;
  8.     a.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";
  9.     (document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]).appendChild(a)
  10. })();
  11.  
  12. function circles(a) {
  13.     this.init(a)
  14. }
  15. circles.prototype = {
  16.     context: null,
  17.     prevMouseX: null,
  18.     prevMouseY: null,
  19.     points: null,
  20.     count: null,
  21.     init: function (a) {
  22.         this.context = a;
  23.         this.context.lineWidth = 1;
  24.         this.context.globalCompositeOperation = "source-over";
  25.         this.points = new Array()
  26.     },
  27.     destroy: function () {},
  28.     strokeStart: function (b, a) {
  29.         this.prevMouseX = b;
  30.         this.prevMouseY = a;
  31.         this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.1)"
  32.     },
  33.     stroke: function (e, b) {
  34.         var g, l, k, h, f, c, j, a;
  35.         this.points.push([e, b]);
  36.         l = e - this.prevMouseX;
  37.         k = b - this.prevMouseY;
  38.         h = Math.sqrt(l * l + k * k) * 2;
  39.         f = Math.floor(e / 100) * 100 + 50;
  40.         c = Math.floor(b / 100) * 100 + 50;
  41.         j = Math.floor(Math.random() * 10);
  42.         a = h / j;
  43.         for (g = 0; g < j; g++) {
  44.             this.context.beginPath();
  45.             this.context.arc(f, c, (j - g) * a, 0, Math.PI * 2, true);
  46.             this.context.stroke()
  47.         }
  48.         this.prevMouseX = e;
  49.         this.prevMouseY = b
  50.     },
  51.     strokeEnd: function (b, a) {}
  52. };
  53.  
  54. function chrome(a) {
  55.     this.init(a)
  56. }
  57. chrome.prototype = {
  58.     context: null,
  59.     prevMouseX: null,
  60.     prevMouseY: null,
  61.     points: null,
  62.     count: null,
  63.     init: function (a) {
  64.         this.context = a;
  65.         this.context.lineWidth = 1;
  66.         if (RegExp(" AppleWebKit/").test(navigator.userAgent)) {
  67.             this.context.globalCompositeOperation = "darker"
  68.         }
  69.         this.points = new Array();
  70.         this.count = 0
  71.     },
  72.     destroy: function () {},
  73.     strokeStart: function (b, a) {
  74.         this.prevMouseX = b;
  75.         this.prevMouseY = a
  76.     },
  77.     stroke: function (f, c) {
  78.         var e, b, a, g;
  79.         this.points.push([f, c]);
  80.         this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.1)";
  81.         this.context.beginPath();
  82.         this.context.moveTo(this.prevMouseX, this.prevMouseY);
  83.         this.context.lineTo(f, c);
  84.         this.context.stroke();
  85.         for (e = 0; e < this.points.length; e++) {
  86.             b = this.points[e][0] - this.points[this.count][0];
  87.             a = this.points[e][1] - this.points[this.count][1];
  88.             g = b * b + a * a;
  89.             if (g < 1000) {
  90.                 this.context.strokeStyle = "rgba(" + Math.floor(Math.random() * 255) + ", " + Math.floor(Math.random() * 255) + ", " + Math.floor(Math.random() * 255) + ", 0.1 )";
  91.                 this.context.beginPath();
  92.                 this.context.moveTo(this.points[this.count][0] + (b * 0.2), this.points[this.count][1] + (a * 0.2));
  93.                 this.context.lineTo(this.points[e][0] - (b * 0.2), this.points[e][1] - (a * 0.2));
  94.                 this.context.stroke()
  95.             }
  96.         }
  97.         this.prevMouseX = f;
  98.         this.prevMouseY = c;
  99.         this.count++
  100.     },
  101.     strokeEnd: function (b, a) {}
  102. };
  103.  
  104. function fur(a) {
  105.     this.init(a)
  106. }
  107. fur.prototype = {
  108.     context: null,
  109.     prevMouseX: null,
  110.     prevMouseY: null,
  111.     points: null,
  112.     count: null,
  113.     init: function (a) {
  114.         this.context = a;
  115.         this.context.lineWidth = 1;
  116.         this.points = new Array();
  117.         this.count = 0
  118.     },
  119.     destroy: function () {},
  120.     strokeStart: function (b, a) {
  121.         this.prevMouseX = b;
  122.         this.prevMouseY = a;
  123.         this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.1)"
  124.     },
  125.     stroke: function (f, c) {
  126.         var e, b, a, g;
  127.         this.points.push([f, c]);
  128.         this.context.beginPath();
  129.         this.context.moveTo(this.prevMouseX, this.prevMouseY);
  130.         this.context.lineTo(f, c);
  131.         this.context.stroke();
  132.         for (e = 0; e < this.points.length; e++) {
  133.             b = this.points[e][0] - this.points[this.count][0];
  134.             a = this.points[e][1] - this.points[this.count][1];
  135.             g = b * b + a * a;
  136.             if (g < 2000 && Math.random() > g / 2000) {
  137.                 this.context.beginPath();
  138.                 this.context.moveTo(f + (b * 0.5), c + (a * 0.5));
  139.                 this.context.lineTo(f - (b * 0.5), c - (a * 0.5));
  140.                 this.context.stroke()
  141.             }
  142.         }
  143.         this.prevMouseX = f;
  144.         this.prevMouseY = c;
  145.         this.count++
  146.     },
  147.     strokeEnd: function (b, a) {}
  148. };
  149.  
  150. function grid(a) {
  151.     this.init(a)
  152. }
  153. grid.prototype = {
  154.     context: null,
  155.     init: function (a) {
  156.         this.context = a;
  157.         this.context.lineWidth = 1;
  158.         if (RegExp(" AppleWebKit/").test(navigator.userAgent)) {
  159.             this.context.globalCompositeOperation = "darker"
  160.         }
  161.     },
  162.     destroy: function () {},
  163.     strokeStart: function (b, a) {
  164.         this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.01)"
  165.     },
  166.     stroke: function (f, d) {
  167.         var e, a, g, c, b;
  168.         a = Math.round(f / 100) * 100;
  169.         g = Math.round(d / 100) * 100;
  170.         c = (a - f) * 10;
  171.         b = (g - d) * 10;
  172.         for (e = 0; e < 50; e++) {
  173.             this.context.beginPath();
  174.             this.context.moveTo(a, g);
  175.             this.context.quadraticCurveTo(f + Math.random() * c, d + Math.random() * b, a, g);
  176.             this.context.stroke()
  177.         }
  178.     },
  179.     strokeEnd: function (b, a) {}
  180. };
  181.  
  182. function longfur(a) {
  183.     this.init(a)
  184. }
  185. longfur.prototype = {
  186.     context: null,
  187.     points: null,
  188.     count: null,
  189.     init: function (a) {
  190.         this.context = a;
  191.         this.context.lineWidth = 1;
  192.         this.context.globalCompositeOperation = "source-over";
  193.         this.points = new Array();
  194.         this.count = 0
  195.     },
  196.     destroy: function () {},
  197.     strokeStart: function (b, a) {
  198.         this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.05 )"
  199.     },
  200.     stroke: function (g, c) {
  201.         var f, e, b, a, h;
  202.         this.points.push([g, c]);
  203.         for (f = 0; f < this.points.length; f++) {
  204.             e = -Math.random();
  205.             b = this.points[f][0] - this.points[this.count][0];
  206.             a = this.points[f][1] - this.points[this.count][1];
  207.             h = b * b + a * a;
  208.             if (h < 4000 && Math.random() > h / 4000) {
  209.                 this.context.beginPath();
  210.                 this.context.moveTo(this.points[this.count][0] + (b * e), this.points[this.count][1] + (a * e));
  211.                 this.context.lineTo(this.points[f][0] - (b * e) + Math.random() * 2, this.points[f][1] - (a * e) + Math.random() * 2);
  212.                 this.context.stroke()
  213.             }
  214.         }
  215.         this.count++
  216.     },
  217.     strokeEnd: function (b, a) {}
  218. };
  219.  
  220. function ribbon(a) {
  221.     this.init(a)
  222. }
  223. ribbon.prototype = {
  224.     context: null,
  225.     mouseX: null,
  226.     mouseY: null,
  227.     painters: null,
  228.     interval: null,
  229.     init: function (b) {
  230.         this.context = b;
  231.         this.context.lineWidth = 1;
  232.         this.context.globalCompositeOperation = "source-over";
  233.         this.mouseX = SCREEN_WIDTH / 2;
  234.         this.mouseY = SCREEN_HEIGHT / 2;
  235.         this.painters = new Array();
  236.         for (var a = 0; a < 50; a++) {
  237.             this.painters.push({
  238.                 dx: SCREEN_WIDTH / 2,
  239.                 dy: SCREEN_HEIGHT / 2,
  240.                 ax: 0,
  241.                 ay: 0,
  242.                 div: 0.1,
  243.                 ease: Math.random() * 0.2 + 0.6
  244.             })
  245.         }
  246.         this.isDrawing = false;
  247.         this.interval = setInterval(bargs(function (c) {
  248.             c.update();
  249.             return false
  250.         }, this), 1000 / 60)
  251.     },
  252.     destroy: function () {
  253.         clearInterval(this.interval)
  254.     },
  255.     strokeStart: function (c, a) {
  256.         this.mouseX = c;
  257.         this.mouseY = a;
  258.         this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.05 )";
  259.         for (var b = 0; b < this.painters.length; b++) {
  260.             this.painters[b].dx = c;
  261.             this.painters[b].dy = a
  262.         }
  263.         this.shouldDraw = true
  264.     },
  265.     stroke: function (b, a) {
  266.         this.mouseX = b;
  267.         this.mouseY = a
  268.     },
  269.     strokeEnd: function (b, a) {},
  270.     update: function () {
  271.         var a;
  272.         for (a = 0; a < this.painters.length; a++) {
  273.             this.context.beginPath();
  274.             this.context.moveTo(this.painters[a].dx, this.painters[a].dy);
  275.             this.painters[a].dx -= this.painters[a].ax = (this.painters[a].ax + (this.painters[a].dx - this.mouseX) * this.painters[a].div) * this.painters[a].ease;
  276.             this.painters[a].dy -= this.painters[a].ay = (this.painters[a].ay + (this.painters[a].dy - this.mouseY) * this.painters[a].div) * this.painters[a].ease;
  277.             this.context.lineTo(this.painters[a].dx, this.painters[a].dy);
  278.             this.context.stroke()
  279.         }
  280.     }
  281. };
  282.  
  283. function bargs(c) {
  284.     var b, a = [];
  285.     for (b = 1; b < arguments.length; b++) {
  286.         a.push(arguments[b])
  287.     }
  288.     return function () {
  289.         return c.apply(this, a)
  290.     }
  291. }
  292. function shaded(a) {
  293.     this.init(a)
  294. }
  295. shaded.prototype = {
  296.     context: null,
  297.     prevMouseX: null,
  298.     prevMouseY: null,
  299.     points: null,
  300.     count: null,
  301.     init: function (a) {
  302.         this.context = a;
  303.         this.context.lineWidth = 1;
  304.         this.context.globalCompositeOperation = "source-over";
  305.         this.points = new Array();
  306.         this.count = 0
  307.     },
  308.     destroy: function () {},
  309.     strokeStart: function (b, a) {
  310.         this.prevMouseX = b;
  311.         this.prevMouseY = a
  312.     },
  313.     stroke: function (f, c) {
  314.         var e, b, a, g;
  315.         this.points.push([f, c]);
  316.         for (e = 0; e < this.points.length; e++) {
  317.             b = this.points[e][0] - this.points[this.count][0];
  318.             a = this.points[e][1] - this.points[this.count][1];
  319.             g = b * b + a * a;
  320.             if (g < 1000) {
  321.                 this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", " + ((1 - (g / 1000)) * 0.1) + " )";
  322.                 this.context.beginPath();
  323.                 this.context.moveTo(this.points[this.count][0], this.points[this.count][1]);
  324.                 this.context.lineTo(this.points[e][0], this.points[e][1]);
  325.                 this.context.stroke()
  326.             }
  327.         }
  328.         this.prevMouseX = f;
  329.         this.prevMouseY = c;
  330.         this.count++
  331.     },
  332.     strokeEnd: function (b, a) {}
  333. };
  334.  
  335. function sketchy(a) {
  336.     this.init(a)
  337. }
  338. sketchy.prototype = {
  339.     context: null,
  340.     prevMouseX: null,
  341.     prevMouseY: null,
  342.     points: null,
  343.     count: null,
  344.     init: function (a) {
  345.         this.context = a;
  346.         this.context.lineWidth = 1;
  347.         this.context.globalCompositeOperation = "source-over";
  348.         this.points = new Array();
  349.         this.count = 0
  350.     },
  351.     destroy: function () {},
  352.     strokeStart: function (b, a) {
  353.         this.prevMouseX = b;
  354.         this.prevMouseY = a
  355.     },
  356.     stroke: function (f, c) {
  357.         var e, b, a, g;
  358.         this.points.push([f, c]);
  359.         this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.05)";
  360.         this.context.beginPath();
  361.         this.context.moveTo(this.prevMouseX, this.prevMouseY);
  362.         this.context.lineTo(f, c);
  363.         this.context.stroke();
  364.         this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.05 )";
  365.         for (e = 0; e < this.points.length; e++) {
  366.             b = this.points[e][0] - this.points[this.count][0];
  367.             a = this.points[e][1] - this.points[this.count][1];
  368.             g = b * b + a * a;
  369.             if (g < 4000 && Math.random() > g / 2000) {
  370.                 this.context.beginPath();
  371.                 this.context.moveTo(this.points[this.count][0] + (b * 0.3), this.points[this.count][1] + (a * 0.3));
  372.                 this.context.lineTo(this.points[e][0] - (b * 0.3), this.points[e][1] - (a * 0.3));
  373.                 this.context.stroke()
  374.             }
  375.         }
  376.         this.prevMouseX = f;
  377.         this.prevMouseY = c;
  378.         this.count++
  379.     },
  380.     strokeEnd: function (b, a) {}
  381. };
  382.  
  383. function squares(a) {
  384.     this.init(a)
  385. }
  386. squares.prototype = {
  387.     context: null,
  388.     prevMouseX: null,
  389.     prevMouseY: null,
  390.     init: function (a) {
  391.         this.context = a;
  392.         this.context.globalCompositeOperation = "source-over";
  393.         this.context.fillStyle = "rgb(255, 255, 255)";
  394.         this.context.lineWidth = 1
  395.     },
  396.     destroy: function () {},
  397.     strokeStart: function (b, a) {
  398.         this.prevMouseX = b;
  399.         this.prevMouseY = a;
  400.         this.context.strokeStyle = "rgb(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ")"
  401.     },
  402.     stroke: function (f, d) {
  403.         var b, a, g, e, c;
  404.         b = f - this.prevMouseX;
  405.         a = d - this.prevMouseY;
  406.         g = 1.57079633;
  407.         e = Math.cos(g) * b - Math.sin(g) * a;
  408.         c = Math.sin(g) * b + Math.cos(g) * a;
  409.         this.context.beginPath();
  410.         this.context.moveTo(this.prevMouseX - e, this.prevMouseY - c);
  411.         this.context.lineTo(this.prevMouseX + e, this.prevMouseY + c);
  412.         this.context.lineTo(f + e, d + c);
  413.         this.context.lineTo(f - e, d - c);
  414.         this.context.lineTo(this.prevMouseX - e, this.prevMouseY - c);
  415.         this.context.fill();
  416.         this.context.stroke();
  417.         this.prevMouseX = f;
  418.         this.prevMouseY = d
  419.     },
  420.     strokeEnd: function (b, a) {}
  421. };
  422.  
  423. function web(a) {
  424.     this.init(a)
  425. }
  426. web.prototype = {
  427.     context: null,
  428.     prevMouseX: null,
  429.     prevMouseY: null,
  430.     points: null,
  431.     count: null,
  432.     init: function (a) {
  433.         this.context = a;
  434.         this.context.lineWidth = 1;
  435.         this.context.globalCompositeOperation = "source-over";
  436.         this.points = new Array();
  437.         this.count = 0
  438.     },
  439.     destroy: function () {},
  440.     strokeStart: function (b, a) {
  441.         this.prevMouseX = b;
  442.         this.prevMouseY = a
  443.     },
  444.     stroke: function (f, c) {
  445.         var e, b, a, g;
  446.         this.points.push([f, c]);
  447.         this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.5)";
  448.         this.context.beginPath();
  449.         this.context.moveTo(this.prevMouseX, this.prevMouseY);
  450.         this.context.lineTo(f, c);
  451.         this.context.stroke();
  452.         this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.1)";
  453.         for (e = 0; e < this.points.length; e++) {
  454.             b = this.points[e][0] - this.points[this.count][0];
  455.             a = this.points[e][1] - this.points[this.count][1];
  456.             g = b * b + a * a;
  457.             if (g < 2500 && Math.random() > 0.9) {
  458.                 this.context.beginPath();
  459.                 this.context.moveTo(this.points[this.count][0], this.points[this.count][1]);
  460.                 this.context.lineTo(this.points[e][0], this.points[e][1]);
  461.                 this.context.stroke()
  462.             }
  463.         }
  464.         this.prevMouseX = f;
  465.         this.prevMouseY = c;
  466.         this.count++
  467.     },
  468.     strokeEnd: function (b, a) {}
  469. };
  470.  
  471. function ColorSelector() {
  472.     var o, a, d, u, z, f, e, h = 0,
  473.         n = 100,
  474.         k = 270,
  475.         A = 40,
  476.         b, p = Math.PI / 180,
  477.         r, q, t, s, w, m, l;
  478.     o = document.createElement("div");
  479.     o.style.position = "absolute";
  480.     o.style.visibility = "hidden";
  481.     o.onclick = v;
  482.     a = document.createElement("canvas");
  483.     a.width = 200;
  484.     a.height = 200;
  485.     d = a.getContext("2d");
  486.     d.lineWidth = 3;
  487.     f = a.width / 2;
  488.     e = a.height / 2;
  489.     b = (n - h) / A;
  490.  
  491.     function g(E, y, x) {
  492.         var B, C, G, D, F, j, c, H;
  493.         if (x == 0) {
  494.             return [0, 0, 0]
  495.         }
  496.         E /= 60;
  497.         y /= 100;
  498.         x /= 100;
  499.         D = Math.floor(E);
  500.         F = E - D;
  501.         j = x * (1 - y);
  502.         c = x * (1 - (y * F));
  503.         H = x * (1 - (y * (1 - F)));
  504.         switch (D) {
  505.         case 0:
  506.             B = x;
  507.             C = H;
  508.             G = j;
  509.             break;
  510.         case 1:
  511.             B = c;
  512.             C = x;
  513.             G = j;
  514.             break;
  515.         case 2:
  516.             B = j;
  517.             C = x;
  518.             G = H;
  519.             break;
  520.         case 3:
  521.             B = j;
  522.             C = c;
  523.             G = x;
  524.             break;
  525.         case 4:
  526.             B = H;
  527.             C = j;
  528.             G = x;
  529.             break;
  530.         case 5:
  531.             B = x;
  532.             C = j;
  533.             G = c;
  534.             break
  535.         }
  536.         return [B, C, G]
  537.     }
  538.     for (r = 0; r < k; r++) {
  539.         t = g(Math.floor((r / k) * 360), 100, 100);
  540.         s = r / (k / 360) * p;
  541.         for (q = 0; q < A; q++) {
  542.             w = (q / A) * 516 - 258;
  543.             d.strokeStyle = "rgb(" + Math.floor(t[0] * 255 + w) + "," + Math.floor(t[1] * 255 + w) + "," + Math.floor(t[2] * 255 + w) + ")";
  544.             d.beginPath();
  545.             d.moveTo(Math.cos(s) * (b * q + h) + f, Math.sin(s) * (b * q + h) + e);
  546.             d.lineTo(Math.cos(s) * (b * (q + 1) + h) + f, Math.sin(s) * (b * (q + 1) + h) + e);
  547.             d.stroke()
  548.         }
  549.     }
  550.     u = d.getImageData(0, 0, a.width, a.height).data;
  551.     o.appendChild(a);
  552.     z = document.createElement("canvas");
  553.     z.width = 14;
  554.     z.height = 14;
  555.     z.style.position = "absolute";
  556.     z.style.left = ((a.width - 14) / 2) + "px";
  557.     z.style.top = ((a.height - 14) / 2) + "px";
  558.     d = z.getContext("2d");
  559.     d.strokeStyle = "rgba(0, 0, 0, 0.5)";
  560.     d.beginPath();
  561.     d.arc(8, 8, 6, 0, Math.PI * 2, true);
  562.     d.stroke();
  563.     d.strokeStyle = "rgba(256, 256, 256, 0.8)";
  564.     d.beginPath();
  565.     d.arc(7, 7, 6, 0, Math.PI * 2, true);
  566.     d.stroke();
  567.     o.appendChild(z);
  568.  
  569.     function v(c) {
  570.         m = (c.clientX - o.offsetLeft - 7);
  571.         l = (c.clientY - o.offsetTop - 7);
  572.         z.style.left = m + "px";
  573.         z.style.top = l + "px";
  574.         COLOR[0] = u[(m + (l * a.width)) * 4];
  575.         COLOR[1] = u[(m + (l * a.width)) * 4 + 1];
  576.         COLOR[2] = u[(m + (l * a.width)) * 4 + 2]
  577.     }
  578.     return o
  579. }
  580. var i, style, STYLES = ["sketchy", "shaded", "chrome", "fur", "longfur", "web", "", "squares", "ribbon", "", "circles", "grid"],
  581.     COLOR = [0, 0, 0],
  582.     SCREEN_WIDTH = window.innerWidth,
  583.     SCREEN_HEIGHT = window.innerHeight,
  584.     container, menu, selector, option, saveButton, clearButton, canvas, context, colorselector, mouseX = 0,
  585.     mouseY = 0,
  586.     isMenuMouseOver = false,
  587.     isMouseDown = false,
  588.     controlKeyIsDown = false;
  589. init();
  590.  
  591. function init() {
  592.     container = document.getElementById("container");
  593.     menu = document.getElementById("menu");
  594.     menu.style.visibility = "visible";
  595.     menu.onmouseover = onMenuMouseOver;
  596.     menu.onmouseout = onMenuMouseOut;
  597.     colorselector = ColorSelector();
  598.     container.appendChild(colorselector);
  599.     canvas = document.createElement("canvas");
  600.     canvas.width = SCREEN_WIDTH;
  601.     canvas.height = SCREEN_HEIGHT;
  602.     canvas.style.cursor = "crosshair";
  603.     container.appendChild(canvas);
  604.     context = canvas.getContext("2d");
  605.     context.fillStyle = "rgb(255, 255, 255)";
  606.     context.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
  607.     saveButton = document.getElementById("save");
  608.     saveButton.addEventListener("click", save, false);
  609.     clearButton = document.getElementById("clear");
  610.     clearButton.onclick = clear;
  611.     selector = document.getElementById("selector");
  612.     selector.onchange = onSelectorChange;
  613.     for (i = 0; i < STYLES.length; i++) {
  614.         option = document.createElement("option");
  615.         option.id = i;
  616.         option.innerHTML = STYLES[i].toUpperCase();
  617.         selector.appendChild(option)
  618.     }
  619.     if (window.location.hash) {
  620.         var hash = window.location.hash.substr(1, window.location.hash.length);
  621.         for (i = 0; i < STYLES.length; i++) {
  622.             if (hash == STYLES[i]) {
  623.                 style = eval("new " + STYLES[i] + "(context)");
  624.                 selector.selectedIndex = i;
  625.                 break
  626.             }
  627.         }
  628.     }
  629.     if (!style) {
  630.         style = eval("new " + STYLES[0] + "(context)")
  631.     }
  632.     window.onresize = onWindowResize;
  633.     window.onkeydown = onDocumentKeyDown;
  634.     window.onkeyup = onDocumentKeyUp;
  635.     document.onmousedown = onDocumentMouseDown;
  636.     document.onmouseout = onCanvasMouseUp;
  637.     canvas.onmousedown = onCanvasMouseDown;
  638.     canvas.onmouseup = onCanvasMouseUp;
  639.     canvas.onmousemove = onCanvasMouseMove;
  640.     canvas.ontouchstart = onCanvasTouchStart;
  641.     canvas.ontouchend = onCanvasTouchEnd;
  642.     canvas.ontouchmove = onCanvasTouchMove;
  643.     onWindowResize(null)
  644. }
  645. function onWindowResize(a) {
  646.     SCREEN_WIDTH = window.innerWidth;
  647.     SCREEN_HEIGHT = window.innerHeight;
  648.     menu.style.left = ((SCREEN_WIDTH - menu.offsetWidth) / 2) + "px"
  649. }
  650. function onDocumentMouseDown(a) {
  651.     return isMenuMouseOver
  652. }
  653. function onDocumentKeyDown(a) {
  654.     if (controlKeyIsDown) {
  655.         return
  656.     }
  657.     switch (a.keyCode) {
  658.     case 16:
  659.         controlKeyIsDown = true;
  660.         colorselector.style.left = mouseX - 100 + "px";
  661.         colorselector.style.top = mouseY - 100 + "px";
  662.         colorselector.style.visibility = "visible";
  663.         break
  664.     }
  665. }
  666. function onDocumentKeyUp(a) {
  667.     switch (a.keyCode) {
  668.     case 16:
  669.         controlKeyIsDown = false;
  670.         colorselector.style.visibility = "hidden";
  671.         break
  672.     }
  673. }
  674. function onSelectorChange(e) {
  675.     if (STYLES[selector.selectedIndex] == "") {
  676.         return
  677.     }
  678.     style.destroy();
  679.     style = eval("new " + STYLES[selector.selectedIndex] + "(context)");
  680.     window.location.hash = STYLES[selector.selectedIndex]
  681. }
  682. function onMenuMouseOver(a) {
  683.     isMenuMouseOver = true
  684. }
  685. function onMenuMouseOut(a) {
  686.     isMenuMouseOver = false
  687. }
  688. function ondocumentMouseDown(a) {
  689.     return !isMenuMouseOver
  690. }
  691. function onCanvasMouseDown(a) {
  692.     isMouseDown = true;
  693.     style.strokeStart(mouseX, mouseY)
  694. }
  695. function onCanvasMouseUp(a) {
  696.     isMouseDown = false;
  697.     style.strokeEnd(mouseX, mouseY)
  698. }
  699. function onCanvasMouseMove(a) {
  700.     if (!a) {
  701.         a = window.event
  702.     }
  703.     mouseX = a.clientX;
  704.     mouseY = a.clientY;
  705.     if (!isMouseDown) {
  706.         return
  707.     }
  708.     style.stroke(mouseX, mouseY)
  709. }
  710. function onCanvasTouchStart(a) {
  711.     if (a.touches.length == 1) {
  712.         var b = a.touches[0];
  713.         style.strokeStart(b.pageX, b.pageY);
  714.         return false
  715.     }
  716. }
  717. function onCanvasTouchEnd(a) {
  718.     if (a.touches.length == 1) {
  719.         var b = a.touches[0];
  720.         style.strokeEnd(b.pageX, b.pageY);
  721.         return false
  722.     }
  723. }
  724. function onCanvasTouchMove(a) {
  725.     if (a.touches.length == 1) {
  726.         var b = a.touches[0];
  727.         style.stroke(b.pageX, b.pageY);
  728.         return false
  729.     }
  730. }
  731. function save() {
  732.     window.open(canvas.toDataURL("image/png"), "mywindow")
  733. }
  734. function clear() {
  735.     context.globalCompositeOperation = "source-over";
  736.     context.fillStyle = "rgb(255, 255, 255)";
  737.     context.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
  738.     style = eval("new " + STYLES[selector.selectedIndex] + "(context)");
  739.     points = new Array();
  740.     count = 0
  741. };
Advertisement
Add Comment
Please, Sign In to add comment