Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var _gaq = _gaq || [];
- _gaq.push(["_setAccount", "UA-86951-7"]);
- _gaq.push(["_trackPageview"]);
- (function () {
- var a = document.createElement("script");
- a.type = "text/javascript";
- a.async = true;
- a.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";
- (document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]).appendChild(a)
- })();
- function circles(a) {
- this.init(a)
- }
- circles.prototype = {
- context: null,
- prevMouseX: null,
- prevMouseY: null,
- points: null,
- count: null,
- init: function (a) {
- this.context = a;
- this.context.lineWidth = 1;
- this.context.globalCompositeOperation = "source-over";
- this.points = new Array()
- },
- destroy: function () {},
- strokeStart: function (b, a) {
- this.prevMouseX = b;
- this.prevMouseY = a;
- this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.1)"
- },
- stroke: function (e, b) {
- var g, l, k, h, f, c, j, a;
- this.points.push([e, b]);
- l = e - this.prevMouseX;
- k = b - this.prevMouseY;
- h = Math.sqrt(l * l + k * k) * 2;
- f = Math.floor(e / 100) * 100 + 50;
- c = Math.floor(b / 100) * 100 + 50;
- j = Math.floor(Math.random() * 10);
- a = h / j;
- for (g = 0; g < j; g++) {
- this.context.beginPath();
- this.context.arc(f, c, (j - g) * a, 0, Math.PI * 2, true);
- this.context.stroke()
- }
- this.prevMouseX = e;
- this.prevMouseY = b
- },
- strokeEnd: function (b, a) {}
- };
- function chrome(a) {
- this.init(a)
- }
- chrome.prototype = {
- context: null,
- prevMouseX: null,
- prevMouseY: null,
- points: null,
- count: null,
- init: function (a) {
- this.context = a;
- this.context.lineWidth = 1;
- if (RegExp(" AppleWebKit/").test(navigator.userAgent)) {
- this.context.globalCompositeOperation = "darker"
- }
- this.points = new Array();
- this.count = 0
- },
- destroy: function () {},
- strokeStart: function (b, a) {
- this.prevMouseX = b;
- this.prevMouseY = a
- },
- stroke: function (f, c) {
- var e, b, a, g;
- this.points.push([f, c]);
- this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.1)";
- this.context.beginPath();
- this.context.moveTo(this.prevMouseX, this.prevMouseY);
- this.context.lineTo(f, c);
- this.context.stroke();
- for (e = 0; e < this.points.length; e++) {
- b = this.points[e][0] - this.points[this.count][0];
- a = this.points[e][1] - this.points[this.count][1];
- g = b * b + a * a;
- if (g < 1000) {
- this.context.strokeStyle = "rgba(" + Math.floor(Math.random() * 255) + ", " + Math.floor(Math.random() * 255) + ", " + Math.floor(Math.random() * 255) + ", 0.1 )";
- this.context.beginPath();
- this.context.moveTo(this.points[this.count][0] + (b * 0.2), this.points[this.count][1] + (a * 0.2));
- this.context.lineTo(this.points[e][0] - (b * 0.2), this.points[e][1] - (a * 0.2));
- this.context.stroke()
- }
- }
- this.prevMouseX = f;
- this.prevMouseY = c;
- this.count++
- },
- strokeEnd: function (b, a) {}
- };
- function fur(a) {
- this.init(a)
- }
- fur.prototype = {
- context: null,
- prevMouseX: null,
- prevMouseY: null,
- points: null,
- count: null,
- init: function (a) {
- this.context = a;
- this.context.lineWidth = 1;
- this.points = new Array();
- this.count = 0
- },
- destroy: function () {},
- strokeStart: function (b, a) {
- this.prevMouseX = b;
- this.prevMouseY = a;
- this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.1)"
- },
- stroke: function (f, c) {
- var e, b, a, g;
- this.points.push([f, c]);
- this.context.beginPath();
- this.context.moveTo(this.prevMouseX, this.prevMouseY);
- this.context.lineTo(f, c);
- this.context.stroke();
- for (e = 0; e < this.points.length; e++) {
- b = this.points[e][0] - this.points[this.count][0];
- a = this.points[e][1] - this.points[this.count][1];
- g = b * b + a * a;
- if (g < 2000 && Math.random() > g / 2000) {
- this.context.beginPath();
- this.context.moveTo(f + (b * 0.5), c + (a * 0.5));
- this.context.lineTo(f - (b * 0.5), c - (a * 0.5));
- this.context.stroke()
- }
- }
- this.prevMouseX = f;
- this.prevMouseY = c;
- this.count++
- },
- strokeEnd: function (b, a) {}
- };
- function grid(a) {
- this.init(a)
- }
- grid.prototype = {
- context: null,
- init: function (a) {
- this.context = a;
- this.context.lineWidth = 1;
- if (RegExp(" AppleWebKit/").test(navigator.userAgent)) {
- this.context.globalCompositeOperation = "darker"
- }
- },
- destroy: function () {},
- strokeStart: function (b, a) {
- this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.01)"
- },
- stroke: function (f, d) {
- var e, a, g, c, b;
- a = Math.round(f / 100) * 100;
- g = Math.round(d / 100) * 100;
- c = (a - f) * 10;
- b = (g - d) * 10;
- for (e = 0; e < 50; e++) {
- this.context.beginPath();
- this.context.moveTo(a, g);
- this.context.quadraticCurveTo(f + Math.random() * c, d + Math.random() * b, a, g);
- this.context.stroke()
- }
- },
- strokeEnd: function (b, a) {}
- };
- function longfur(a) {
- this.init(a)
- }
- longfur.prototype = {
- context: null,
- points: null,
- count: null,
- init: function (a) {
- this.context = a;
- this.context.lineWidth = 1;
- this.context.globalCompositeOperation = "source-over";
- this.points = new Array();
- this.count = 0
- },
- destroy: function () {},
- strokeStart: function (b, a) {
- this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.05 )"
- },
- stroke: function (g, c) {
- var f, e, b, a, h;
- this.points.push([g, c]);
- for (f = 0; f < this.points.length; f++) {
- e = -Math.random();
- b = this.points[f][0] - this.points[this.count][0];
- a = this.points[f][1] - this.points[this.count][1];
- h = b * b + a * a;
- if (h < 4000 && Math.random() > h / 4000) {
- this.context.beginPath();
- this.context.moveTo(this.points[this.count][0] + (b * e), this.points[this.count][1] + (a * e));
- this.context.lineTo(this.points[f][0] - (b * e) + Math.random() * 2, this.points[f][1] - (a * e) + Math.random() * 2);
- this.context.stroke()
- }
- }
- this.count++
- },
- strokeEnd: function (b, a) {}
- };
- function ribbon(a) {
- this.init(a)
- }
- ribbon.prototype = {
- context: null,
- mouseX: null,
- mouseY: null,
- painters: null,
- interval: null,
- init: function (b) {
- this.context = b;
- this.context.lineWidth = 1;
- this.context.globalCompositeOperation = "source-over";
- this.mouseX = SCREEN_WIDTH / 2;
- this.mouseY = SCREEN_HEIGHT / 2;
- this.painters = new Array();
- for (var a = 0; a < 50; a++) {
- this.painters.push({
- dx: SCREEN_WIDTH / 2,
- dy: SCREEN_HEIGHT / 2,
- ax: 0,
- ay: 0,
- div: 0.1,
- ease: Math.random() * 0.2 + 0.6
- })
- }
- this.isDrawing = false;
- this.interval = setInterval(bargs(function (c) {
- c.update();
- return false
- }, this), 1000 / 60)
- },
- destroy: function () {
- clearInterval(this.interval)
- },
- strokeStart: function (c, a) {
- this.mouseX = c;
- this.mouseY = a;
- this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.05 )";
- for (var b = 0; b < this.painters.length; b++) {
- this.painters[b].dx = c;
- this.painters[b].dy = a
- }
- this.shouldDraw = true
- },
- stroke: function (b, a) {
- this.mouseX = b;
- this.mouseY = a
- },
- strokeEnd: function (b, a) {},
- update: function () {
- var a;
- for (a = 0; a < this.painters.length; a++) {
- this.context.beginPath();
- this.context.moveTo(this.painters[a].dx, this.painters[a].dy);
- 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;
- 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;
- this.context.lineTo(this.painters[a].dx, this.painters[a].dy);
- this.context.stroke()
- }
- }
- };
- function bargs(c) {
- var b, a = [];
- for (b = 1; b < arguments.length; b++) {
- a.push(arguments[b])
- }
- return function () {
- return c.apply(this, a)
- }
- }
- function shaded(a) {
- this.init(a)
- }
- shaded.prototype = {
- context: null,
- prevMouseX: null,
- prevMouseY: null,
- points: null,
- count: null,
- init: function (a) {
- this.context = a;
- this.context.lineWidth = 1;
- this.context.globalCompositeOperation = "source-over";
- this.points = new Array();
- this.count = 0
- },
- destroy: function () {},
- strokeStart: function (b, a) {
- this.prevMouseX = b;
- this.prevMouseY = a
- },
- stroke: function (f, c) {
- var e, b, a, g;
- this.points.push([f, c]);
- for (e = 0; e < this.points.length; e++) {
- b = this.points[e][0] - this.points[this.count][0];
- a = this.points[e][1] - this.points[this.count][1];
- g = b * b + a * a;
- if (g < 1000) {
- this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", " + ((1 - (g / 1000)) * 0.1) + " )";
- this.context.beginPath();
- this.context.moveTo(this.points[this.count][0], this.points[this.count][1]);
- this.context.lineTo(this.points[e][0], this.points[e][1]);
- this.context.stroke()
- }
- }
- this.prevMouseX = f;
- this.prevMouseY = c;
- this.count++
- },
- strokeEnd: function (b, a) {}
- };
- function sketchy(a) {
- this.init(a)
- }
- sketchy.prototype = {
- context: null,
- prevMouseX: null,
- prevMouseY: null,
- points: null,
- count: null,
- init: function (a) {
- this.context = a;
- this.context.lineWidth = 1;
- this.context.globalCompositeOperation = "source-over";
- this.points = new Array();
- this.count = 0
- },
- destroy: function () {},
- strokeStart: function (b, a) {
- this.prevMouseX = b;
- this.prevMouseY = a
- },
- stroke: function (f, c) {
- var e, b, a, g;
- this.points.push([f, c]);
- this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.05)";
- this.context.beginPath();
- this.context.moveTo(this.prevMouseX, this.prevMouseY);
- this.context.lineTo(f, c);
- this.context.stroke();
- this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.05 )";
- for (e = 0; e < this.points.length; e++) {
- b = this.points[e][0] - this.points[this.count][0];
- a = this.points[e][1] - this.points[this.count][1];
- g = b * b + a * a;
- if (g < 4000 && Math.random() > g / 2000) {
- this.context.beginPath();
- this.context.moveTo(this.points[this.count][0] + (b * 0.3), this.points[this.count][1] + (a * 0.3));
- this.context.lineTo(this.points[e][0] - (b * 0.3), this.points[e][1] - (a * 0.3));
- this.context.stroke()
- }
- }
- this.prevMouseX = f;
- this.prevMouseY = c;
- this.count++
- },
- strokeEnd: function (b, a) {}
- };
- function squares(a) {
- this.init(a)
- }
- squares.prototype = {
- context: null,
- prevMouseX: null,
- prevMouseY: null,
- init: function (a) {
- this.context = a;
- this.context.globalCompositeOperation = "source-over";
- this.context.fillStyle = "rgb(255, 255, 255)";
- this.context.lineWidth = 1
- },
- destroy: function () {},
- strokeStart: function (b, a) {
- this.prevMouseX = b;
- this.prevMouseY = a;
- this.context.strokeStyle = "rgb(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ")"
- },
- stroke: function (f, d) {
- var b, a, g, e, c;
- b = f - this.prevMouseX;
- a = d - this.prevMouseY;
- g = 1.57079633;
- e = Math.cos(g) * b - Math.sin(g) * a;
- c = Math.sin(g) * b + Math.cos(g) * a;
- this.context.beginPath();
- this.context.moveTo(this.prevMouseX - e, this.prevMouseY - c);
- this.context.lineTo(this.prevMouseX + e, this.prevMouseY + c);
- this.context.lineTo(f + e, d + c);
- this.context.lineTo(f - e, d - c);
- this.context.lineTo(this.prevMouseX - e, this.prevMouseY - c);
- this.context.fill();
- this.context.stroke();
- this.prevMouseX = f;
- this.prevMouseY = d
- },
- strokeEnd: function (b, a) {}
- };
- function web(a) {
- this.init(a)
- }
- web.prototype = {
- context: null,
- prevMouseX: null,
- prevMouseY: null,
- points: null,
- count: null,
- init: function (a) {
- this.context = a;
- this.context.lineWidth = 1;
- this.context.globalCompositeOperation = "source-over";
- this.points = new Array();
- this.count = 0
- },
- destroy: function () {},
- strokeStart: function (b, a) {
- this.prevMouseX = b;
- this.prevMouseY = a
- },
- stroke: function (f, c) {
- var e, b, a, g;
- this.points.push([f, c]);
- this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.5)";
- this.context.beginPath();
- this.context.moveTo(this.prevMouseX, this.prevMouseY);
- this.context.lineTo(f, c);
- this.context.stroke();
- this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", 0.1)";
- for (e = 0; e < this.points.length; e++) {
- b = this.points[e][0] - this.points[this.count][0];
- a = this.points[e][1] - this.points[this.count][1];
- g = b * b + a * a;
- if (g < 2500 && Math.random() > 0.9) {
- this.context.beginPath();
- this.context.moveTo(this.points[this.count][0], this.points[this.count][1]);
- this.context.lineTo(this.points[e][0], this.points[e][1]);
- this.context.stroke()
- }
- }
- this.prevMouseX = f;
- this.prevMouseY = c;
- this.count++
- },
- strokeEnd: function (b, a) {}
- };
- function ColorSelector() {
- var o, a, d, u, z, f, e, h = 0,
- n = 100,
- k = 270,
- A = 40,
- b, p = Math.PI / 180,
- r, q, t, s, w, m, l;
- o = document.createElement("div");
- o.style.position = "absolute";
- o.style.visibility = "hidden";
- o.onclick = v;
- a = document.createElement("canvas");
- a.width = 200;
- a.height = 200;
- d = a.getContext("2d");
- d.lineWidth = 3;
- f = a.width / 2;
- e = a.height / 2;
- b = (n - h) / A;
- function g(E, y, x) {
- var B, C, G, D, F, j, c, H;
- if (x == 0) {
- return [0, 0, 0]
- }
- E /= 60;
- y /= 100;
- x /= 100;
- D = Math.floor(E);
- F = E - D;
- j = x * (1 - y);
- c = x * (1 - (y * F));
- H = x * (1 - (y * (1 - F)));
- switch (D) {
- case 0:
- B = x;
- C = H;
- G = j;
- break;
- case 1:
- B = c;
- C = x;
- G = j;
- break;
- case 2:
- B = j;
- C = x;
- G = H;
- break;
- case 3:
- B = j;
- C = c;
- G = x;
- break;
- case 4:
- B = H;
- C = j;
- G = x;
- break;
- case 5:
- B = x;
- C = j;
- G = c;
- break
- }
- return [B, C, G]
- }
- for (r = 0; r < k; r++) {
- t = g(Math.floor((r / k) * 360), 100, 100);
- s = r / (k / 360) * p;
- for (q = 0; q < A; q++) {
- w = (q / A) * 516 - 258;
- d.strokeStyle = "rgb(" + Math.floor(t[0] * 255 + w) + "," + Math.floor(t[1] * 255 + w) + "," + Math.floor(t[2] * 255 + w) + ")";
- d.beginPath();
- d.moveTo(Math.cos(s) * (b * q + h) + f, Math.sin(s) * (b * q + h) + e);
- d.lineTo(Math.cos(s) * (b * (q + 1) + h) + f, Math.sin(s) * (b * (q + 1) + h) + e);
- d.stroke()
- }
- }
- u = d.getImageData(0, 0, a.width, a.height).data;
- o.appendChild(a);
- z = document.createElement("canvas");
- z.width = 14;
- z.height = 14;
- z.style.position = "absolute";
- z.style.left = ((a.width - 14) / 2) + "px";
- z.style.top = ((a.height - 14) / 2) + "px";
- d = z.getContext("2d");
- d.strokeStyle = "rgba(0, 0, 0, 0.5)";
- d.beginPath();
- d.arc(8, 8, 6, 0, Math.PI * 2, true);
- d.stroke();
- d.strokeStyle = "rgba(256, 256, 256, 0.8)";
- d.beginPath();
- d.arc(7, 7, 6, 0, Math.PI * 2, true);
- d.stroke();
- o.appendChild(z);
- function v(c) {
- m = (c.clientX - o.offsetLeft - 7);
- l = (c.clientY - o.offsetTop - 7);
- z.style.left = m + "px";
- z.style.top = l + "px";
- COLOR[0] = u[(m + (l * a.width)) * 4];
- COLOR[1] = u[(m + (l * a.width)) * 4 + 1];
- COLOR[2] = u[(m + (l * a.width)) * 4 + 2]
- }
- return o
- }
- var i, style, STYLES = ["sketchy", "shaded", "chrome", "fur", "longfur", "web", "", "squares", "ribbon", "", "circles", "grid"],
- COLOR = [0, 0, 0],
- SCREEN_WIDTH = window.innerWidth,
- SCREEN_HEIGHT = window.innerHeight,
- container, menu, selector, option, saveButton, clearButton, canvas, context, colorselector, mouseX = 0,
- mouseY = 0,
- isMenuMouseOver = false,
- isMouseDown = false,
- controlKeyIsDown = false;
- init();
- function init() {
- container = document.getElementById("container");
- menu = document.getElementById("menu");
- menu.style.visibility = "visible";
- menu.onmouseover = onMenuMouseOver;
- menu.onmouseout = onMenuMouseOut;
- colorselector = ColorSelector();
- container.appendChild(colorselector);
- canvas = document.createElement("canvas");
- canvas.width = SCREEN_WIDTH;
- canvas.height = SCREEN_HEIGHT;
- canvas.style.cursor = "crosshair";
- container.appendChild(canvas);
- context = canvas.getContext("2d");
- context.fillStyle = "rgb(255, 255, 255)";
- context.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
- saveButton = document.getElementById("save");
- saveButton.addEventListener("click", save, false);
- clearButton = document.getElementById("clear");
- clearButton.onclick = clear;
- selector = document.getElementById("selector");
- selector.onchange = onSelectorChange;
- for (i = 0; i < STYLES.length; i++) {
- option = document.createElement("option");
- option.id = i;
- option.innerHTML = STYLES[i].toUpperCase();
- selector.appendChild(option)
- }
- if (window.location.hash) {
- var hash = window.location.hash.substr(1, window.location.hash.length);
- for (i = 0; i < STYLES.length; i++) {
- if (hash == STYLES[i]) {
- style = eval("new " + STYLES[i] + "(context)");
- selector.selectedIndex = i;
- break
- }
- }
- }
- if (!style) {
- style = eval("new " + STYLES[0] + "(context)")
- }
- window.onresize = onWindowResize;
- window.onkeydown = onDocumentKeyDown;
- window.onkeyup = onDocumentKeyUp;
- document.onmousedown = onDocumentMouseDown;
- document.onmouseout = onCanvasMouseUp;
- canvas.onmousedown = onCanvasMouseDown;
- canvas.onmouseup = onCanvasMouseUp;
- canvas.onmousemove = onCanvasMouseMove;
- canvas.ontouchstart = onCanvasTouchStart;
- canvas.ontouchend = onCanvasTouchEnd;
- canvas.ontouchmove = onCanvasTouchMove;
- onWindowResize(null)
- }
- function onWindowResize(a) {
- SCREEN_WIDTH = window.innerWidth;
- SCREEN_HEIGHT = window.innerHeight;
- menu.style.left = ((SCREEN_WIDTH - menu.offsetWidth) / 2) + "px"
- }
- function onDocumentMouseDown(a) {
- return isMenuMouseOver
- }
- function onDocumentKeyDown(a) {
- if (controlKeyIsDown) {
- return
- }
- switch (a.keyCode) {
- case 16:
- controlKeyIsDown = true;
- colorselector.style.left = mouseX - 100 + "px";
- colorselector.style.top = mouseY - 100 + "px";
- colorselector.style.visibility = "visible";
- break
- }
- }
- function onDocumentKeyUp(a) {
- switch (a.keyCode) {
- case 16:
- controlKeyIsDown = false;
- colorselector.style.visibility = "hidden";
- break
- }
- }
- function onSelectorChange(e) {
- if (STYLES[selector.selectedIndex] == "") {
- return
- }
- style.destroy();
- style = eval("new " + STYLES[selector.selectedIndex] + "(context)");
- window.location.hash = STYLES[selector.selectedIndex]
- }
- function onMenuMouseOver(a) {
- isMenuMouseOver = true
- }
- function onMenuMouseOut(a) {
- isMenuMouseOver = false
- }
- function ondocumentMouseDown(a) {
- return !isMenuMouseOver
- }
- function onCanvasMouseDown(a) {
- isMouseDown = true;
- style.strokeStart(mouseX, mouseY)
- }
- function onCanvasMouseUp(a) {
- isMouseDown = false;
- style.strokeEnd(mouseX, mouseY)
- }
- function onCanvasMouseMove(a) {
- if (!a) {
- a = window.event
- }
- mouseX = a.clientX;
- mouseY = a.clientY;
- if (!isMouseDown) {
- return
- }
- style.stroke(mouseX, mouseY)
- }
- function onCanvasTouchStart(a) {
- if (a.touches.length == 1) {
- var b = a.touches[0];
- style.strokeStart(b.pageX, b.pageY);
- return false
- }
- }
- function onCanvasTouchEnd(a) {
- if (a.touches.length == 1) {
- var b = a.touches[0];
- style.strokeEnd(b.pageX, b.pageY);
- return false
- }
- }
- function onCanvasTouchMove(a) {
- if (a.touches.length == 1) {
- var b = a.touches[0];
- style.stroke(b.pageX, b.pageY);
- return false
- }
- }
- function save() {
- window.open(canvas.toDataURL("image/png"), "mywindow")
- }
- function clear() {
- context.globalCompositeOperation = "source-over";
- context.fillStyle = "rgb(255, 255, 255)";
- context.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
- style = eval("new " + STYLES[selector.selectedIndex] + "(context)");
- points = new Array();
- count = 0
- };
Advertisement
Add Comment
Please, Sign In to add comment