Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function (canvas, v) {
- function onload() {
- retrieveRegions();
- setInterval(retrieveRegions, 18E4);
- B = S = document.getElementById("canvas");
- ctx = B.getContext("2d");
- B.onmousedown = function (a) {
- if (fa) {
- var b = a.clientX - (5 + width / 5 / 2)
- , c = a.clientY - (5 + width / 5 / 2);
- if (Math.sqrt(b * b + c * c) <= width / 5 / 2) {
- G();
- networkSendCharlie(17);
- return
- }
- }
- J = a.clientX;
- K = a.clientY;
- interpolate();
- G()
- };
- B.onmousemove = function (a) {
- J = a.clientX;
- K = a.clientY;
- interpolate()
- };
- B.onmouseup = function (a) {};
- var a = !1
- , b = !1
- , c = !1;
- canvas.onkeydown = function (f) {
- 32 != f.keyCode || a || (G(), networkSendCharlie(17), a = !0);
- 81 != f.keyCode || b || (networkSendCharlie(18), b = !0);
- 87 != f.keyCode || c || (G(), networkSendCharlie(21), c = !0)
- };
- canvas.onkeyup = function (f) {
- 32 == f.keyCode && (a = !1);
- 87 == f.keyCode && (c = !1);
- 81 == f.keyCode && b && (networkSendCharlie(19), b = !1)
- };
- canvas.onblur = function () {
- networkSendCharlie(19);
- c = b = a = !1
- };
- canvas.onresize = onWindowUpdate;
- onWindowUpdate();
- canvas.requestAnimationFrame ? canvas.requestAnimationFrame(renderLoop) : setInterval(render, 1E3 / 60);
- setInterval(G, 100);
- ia(v("#region")
- .val())
- }
- // something to do with quadtrees
- function addCirclesToQuadTree() {
- for (var a = Number.POSITIVE_INFINITY, b = Number.POSITIVE_INFINITY, c = Number.NEGATIVE_INFINITY, f = Number.NEGATIVE_INFINITY, d = 0, e = 0; e < circleArray.length; e++) d = Math.max(circleArray[e].size, d), a = Math.min(circleArray[e].x, a), b = Math.min(circleArray[e].y, b), c = Math.max(circleArray[e].x, c), f = Math.max(circleArray[e].y, f);
- quadTree = QUAD.init({
- minX: a - (d + 100)
- , minY: b - (d + 100)
- , maxX: c + (d + 100)
- , maxY: f + (d + 100)
- });
- for (e = 0; e < circleArray.length; e++)
- if (a = circleArray[e], a.shouldRender())
- for (b = 0; b < a.points.length; ++b) quadTree.insert(a.points[b])
- }
- // interpolation?
- function interpolate() {
- L = (J - width / 2) / zoom + x;
- M = (K - height / 2) / zoom + y
- }
- function retrieveRegions() {
- N == null && (N = {}, v("#region")
- .children()
- .each(function () {
- var a = v(this)
- , b = a.val();
- b && (N[b] = a.text())
- }));
- v.get("http://m.agar.io/info", function (a) {
- for (var b in a.regions) v('#region option[value="' + b + '"]')
- .text(N[b] + " (" + a.regions[b].numPlayers + " players)")
- }
- , "json")
- }
- function ia(a) {
- a && a != W && (W = a, startConnect())
- }
- function tryConnect() {
- v.ajax("http://m.agar.io/", {
- error: function () {
- setTimeout(tryConnect, 1E3)
- }
- , success: function (a) {
- a = a.split("\n");
- openSocket("ws://" + a[0])
- }
- , dataType: "text"
- , method: "POST"
- , cache: !1
- , crossDomain: !0
- , data: W || "?"
- })
- }
- function startConnect() {
- v("#connecting")
- .show();
- tryConnect()
- }
- function openSocket(address) {
- hSocket && (hSocket.onopen = null, hSocket.onmessage = null, hSocket.onclose = null, hSocket.close(), hSocket = null);
- D = [];
- myCircles = [];
- z = {};
- circleArray = [];
- E = [];
- q = [];
- console.log("Connecting to " + address);
- hSocket = new WebSocket(address);
- hSocket.binaryType = "arraybuffer";
- hSocket.onopen = wa;
- hSocket.onmessage = xa;
- hSocket.onclose = onSocketClose;
- hSocket.onerror = function () {
- console.log("socket error")
- }
- }
- function wa(a) {
- v("#connecting")
- .hide();
- console.log("socket open");
- a = new ArrayBuffer(5);
- var b = new DataView(a);
- b.setUint8(0, 255);
- b.setUint32(1, 1, !0);
- hSocket.send(a);
- sendHandshake()
- }
- function onSocketClose(a) {
- console.log("socket close");
- setTimeout(startConnect, 500)
- }
- function xa(a) {
- function b() {
- for (var a = "";;) {
- var b = f.getUint16(c, !0);
- c += 2;
- if (0 == b) break;
- a += String.fromCharCode(b)
- }
- return a
- }
- var c = 1
- , f = new DataView(a.data);
- switch (f.getUint8(0)) {
- case 16:
- za(f);
- break;
- case 20:
- myCircles = [];
- D = [];
- break;
- case 32:
- D.push(f.getUint32(1, !0));
- break;
- case 48:
- for (q = []; c < f.byteLength;) q.push(b());
- drawLeaderboard();
- break;
- case 49:
- a = f.getUint32(c, !0);
- c += 4;
- q = [];
- for (var d = 0; d < a; ++d) f.getUint32(c, !0), c += 4, q.push(b());
- drawLeaderboard();
- break;
- case 64:
- X = f.getFloat64(1, !0), Y = f.getFloat64(9, !0), Z = f.getFloat64(17, !0), $ = f.getFloat64(25, !0), 0 == myCircles.length && (x = (Z + X) / 2, y = ($ + Y) / 2)
- }
- }
- function za(a) {
- F = +new Date;
- var b = Math.random()
- , c = 1;
- aa = !1;
- for (var f = a.getUint16(c, !0), c = c + 2, d = 0; d < f; ++d) {
- var e = z[a.getUint32(c, !0)]
- , t = z[a.getUint32(c + 4, !0)]
- , c = c + 8;
- e &&
- t && (t.destroy(), t.ox = t.x, t.oy = t.y, t.oSize = t.size, t.nx = e.x, t.ny = e.y, t.nSize = t.size, t.updateTime = F)
- }
- for (;;) {
- f = a.getUint32(c, !0);
- c += 4;
- if (0 == f) break;
- var d = a.getFloat64(c, !0)
- , c = c + 8
- , e = a.getFloat64(c, !0)
- , c = c + 8
- , t = a.getFloat64(c, !0)
- , c = c + 8
- , l = a.getUint8(c++)
- , h = !1;
- if (0 == l) h = !0, l = "#33FF33";
- else if (255 == l) {
- var h = a.getUint8(c++)
- , l = a.getUint8(c++)
- , g = a.getUint8(c++)
- , l = oa(h << 16 | l << 8 | g)
- , g = a.getUint8(c++)
- , h = !!(g & 1);
- g & 2 && (c += 4);
- g & 4 && (c += 8);
- g & 8 && (c += 16)
- } else {
- var l = 63487 | l << 16
- , k = (l >> 16 & 255) / 255 * 360
- , n = (l >> 8 & 255) / 255
- , l = (l >>
- 0 & 255) / 255;
- if (0 == n) l = l << 16 | l << 8 | l << 0;
- else {
- var k = k / 60
- , g = ~~k
- , u = k - g
- , k = l * (1 - n)
- , s = l * (1 - n * u)
- , n = l * (1 - n * (1 - u))
- , p = u = 0
- , q = 0;
- switch (g % 6) {
- case 0:
- u = l;
- p = n;
- q = k;
- break;
- case 1:
- u = s;
- p = l;
- q = k;
- break;
- case 2:
- u = k;
- p = l;
- q = n;
- break;
- case 3:
- u = k;
- p = s;
- q = l;
- break;
- case 4:
- u = n;
- p = k;
- q = l;
- break;
- case 5:
- u = l, p = k, q = s
- }
- u = ~~(255 * u) & 255;
- p = ~~(255 * p) & 255;
- q = ~~(255 * q) & 255;
- l = u << 16 | p << 8 | q
- }
- l = oa(l)
- }
- for (g = "";;) {
- k = a.getUint16(c, !0);
- c += 2;
- if (0 == k) break;
- g += String.fromCharCode(k)
- }
- k = null;
- z.hasOwnProperty(f) ? (k = z[f], k.updatePos(), k.ox = k.x, k.oy = k.y, k.oSize = k.size, k.color =
- l) : (k = new createCircle(f, d, e, t, l, h, g), k.pX = d, k.pY = e);
- k.nx = d;
- k.ny = e;
- k.nSize = t;
- k.updateCode = b;
- k.updateTime = F; - 1 != D.indexOf(f) && -1 == myCircles.indexOf(k) && (document.getElementById("overlays")
- .style.display = "none", myCircles.push(k), 1 == myCircles.length && (x = k.x, y = k.y))
- }
- a.getUint16(c, !0);
- c += 2;
- e = a.getUint32(c, !0);
- c += 4;
- for (d = 0; d < e; d++) f = a.getUint32(c, !0), c += 4, z[f] && (z[f].updateCode = b);
- for (d = 0; d < circleArray.length; d++) circleArray[d].updateCode != b && circleArray[d--].destroy();
- aa && 0 == myCircles.length && v("#overlays")
- .fadeIn(3E3)
- }
- function G() {
- if (null != hSocket && hSocket.readyState == hSocket.OPEN) {
- var a = J - width / 2
- , b = K - height / 2;
- 64 > a * a + b * b || qa == L && ra == M || (qa = L, ra = M, a = new ArrayBuffer(21), b = new DataView(a), b.setUint8(0, 16), b.setFloat64(1, L, !0), b.setFloat64(9, M, !0), b.setUint32(17, 0, !0), hSocket.send(a))
- }
- }
- // send handshake (??)
- function sendHandshake() {
- if (null != hSocket && hSocket.readyState == hSocket.OPEN && null != HArray) {
- var arrayBuffer = new ArrayBuffer(1 + 2 * HArray.length)
- , bufferDataView = new DataView(arrayBuffer);
- bufferDataView.setUint8(0, 0);
- for (var c = 0; c < HArray.length; ++c) bufferDataView.setUint16(1 + 2 * c, HArray.charCodeAt(c), !0);
- hSocket.send(arrayBuffer)
- }
- }
- // don't know what this does, sends one UInt8
- function networkSendCharlie(a) {
- if (null != hSocket && hSocket.readyState == hSocket.OPEN) {
- var b = new ArrayBuffer(1);
- (new DataView(b))
- .setUint8(0, a);
- hSocket.send(b)
- }
- }
- function renderLoop() {
- render();
- canvas.requestAnimationFrame(renderLoop)
- }
- // on window update?
- function onWindowUpdate() {
- width = canvas.innerWidth;
- height = canvas.innerHeight;
- S.width = B.width = width;
- S.height = B.height = height;
- render()
- }
- function calculateZoom() {
- // myCircles (probably) stores the circles the player controls
- if (0 != myCircles.length) {
- for (var a = 0, b = 0; b < myCircles.length; b++) a += myCircles[b].size;
- a = Math.pow(Math.min(64 / a, 1), .4) * Math.max(height / 965, width / 1920);
- zoom = (9 * zoom + a) / 10
- }
- }
- function render() {
- var a = +new Date;
- ++Ba;
- calculateZoom();
- F = +new Date;
- // draw update circles
- if (0 < myCircles.length) {
- for (var b = 0, c = 0, f = 0; f < myCircles.length; f++) myCircles[f].updatePos(), b += myCircles[f].x / myCircles.length, c += myCircles[f].y / myCircles.length;
- x = (x + b) / 2;
- y = (y + c) / 2
- }
- addCirclesToQuadTree();
- interpolate();
- ctx.clearRect(0, 0, width, height);
- ctx.fillStyle = ba ? "#111111" :
- "#F2FBFF";
- ctx.fillRect(0, 0, width, height);
- ctx.save();
- ctx.strokeStyle = ba ? "#AAAAAA" : "#000000";
- ctx.globalAlpha = .2;
- ctx.scale(zoom, zoom);
- b = width / zoom;
- c = height / zoom;
- for (f = -.5 + (-x + b / 2) % 50; f < b; f += 50) ctx.beginPath(), ctx.moveTo(f, 0), ctx.lineTo(f, c), ctx.stroke();
- for (f = -.5 + (-y + c / 2) % 50; f < c; f += 50) ctx.beginPath(), ctx.moveTo(0, f), ctx.lineTo(b, f), ctx.stroke();
- ctx.restore();
- circleArray.sort(function (circleA, circleB) {
- return circleA.size == circleB.size ? circleA.id - circleB.id : circleA.size - circleB.size
- });
- ctx.save();
- ctx.translate(width / 2, height / 2);
- ctx.scale(zoom, zoom);
- ctx.translate(-x, -y);
- for (f = 0; f < E.length; f++) E[f].draw();
- for (f = 0; f < circleArray.length; f++) circleArray[f].draw();
- ctx.restore();
- leaderBoardCanvas && 0 != q.length && ctx.drawImage(leaderBoardCanvas, width - leaderBoardCanvas.width - 10, 10);
- I = Math.max(I, calculateScore());
- 0 != I && (null == O && (O = new P(24, "#FFFFFF")), O.setValue("Score: " + ~~(I / 100)), c = O.render(), b = c.width, ctx.globalAlpha = .2, ctx.fillStyle = "#000000", ctx.fillRect(10, height - 10 - 24 - 10, b + 10, 34), ctx.globalAlpha = 1, ctx.drawImage(c, 15, height - 10 - 24 - 5));
- Da();
- a = +new Date - a;
- a > 1E3 / 60 ? w -= .01 : a < 1E3 / 65 && (w += .01);.4 > w && (w = .4);
- 1 < w && (w = 1)
- }
- function Da() {
- if (fa && ca.width) {
- var a = width / 5;
- ctx.drawImage(ca, 5, 5, a, a)
- }
- }
- // calculate the score for the circles owned by the player
- function calculateScore() {
- for (var a = 0, b = 0; b < myCircles.length; b++) {
- a += myCircles[b].nSize * myCircles[b].nSize;
- }
- return a
- }
- function drawLeaderboard() {
- if (0 != q.length)
- if (Q) {
- leaderBoardCanvas = document.createElement("canvas");
- var lCtx = leaderBoardCanvas.getContext("2d")
- , b = 60 + 24 * q.length
- , c = Math.min(200, .3 * width) / 200;
- leaderBoardCanvas.width = 200 * c;
- leaderBoardCanvas.height = b * c;
- lCtx.scale(c, c);
- lCtx.globalAlpha = .4;
- lCtx.fillStyle = "#000000";
- lCtx.fillRect(0, 0, 200, b);
- lCtx.globalAlpha = 1;
- lCtx.fillStyle = "#FFFFFF";
- c = null;
- c = "Leaderboard";
- lCtx.font = "30px Ubuntu";
- lCtx.fillText(c, 100 - lCtx.measureText(c)
- .width / 2, 40);
- lCtx.font = "20px Ubuntu";
- for (b = 0; b < q.length; ++b) c = q[b] || "An unnamed cell", Q || 0 != myCircles.length && myCircles[0].name == c || (c = "An unnamed cell"), c = b +
- 1 + ". " + c, lCtx.fillText(c, 100 - lCtx.measureText(c)
- .width / 2, 70 + 24 * b)
- } else leaderBoardCanvas = null
- }
- function createCircle(id, ox, oy, size, color, virus, name) {
- circleArray.push(this);
- z[id] = this;
- this.id = id;
- this.ox = this.x = ox;
- this.oy = this.y = oy;
- this.oSize = this.size = size;
- this.color = color;
- this.isVirus = virus;
- this.points = [];
- this.pointsAcc = [];
- this.createPoints();
- this.setName(name)
- }
- function oa(a) {
- for (a = a.toString(16); a.length < 6;) a = "0" + a;
- return "#" + a
- }
- function P(a, b, c, d) {
- a && (this._size = a);
- b && (this._color = b);
- this._stroke = !!c;
- d && (this._strokeColor = d)
- }
- if ("agar.io" != canvas.location.hostname && "localhost" != canvas.location.hostname && "10.10.2.13" != canvas.location.hostname) {
- canvas.location = "http://agar.io/";
- } else {
- var S, ctx, B, width, height, quadTree = null
- , hSocket = null
- , x = 0
- , y = 0
- , D = []
- , myCircles = []
- , z = {}
- , circleArray = []
- , E = []
- , q = []
- , J = 0
- , K = 0
- , L = -1
- , M = -1
- , Ba = 0
- , F = 0
- , HArray = null
- , X = 0
- , Y = 0
- , Z = 1E4
- , $ = 1E4
- , zoom = 1
- , W = null
- , sa = !0
- , Q = !0
- , da = !1
- , aa = !1
- , I = 0
- , ba = !1
- , ta = !1
- , fa = "ontouchstart" in canvas && /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
- , ca = new Image;
- ca.src = "img/split.png";
- var N = null;
- canvas.setNick = function (a) {
- v("#adsBottom")
- .hide();
- HArray = a;
- sendHandshake();
- v("#overlays")
- .hide();
- I = 0
- };
- canvas.setRegion = ia;
- canvas.setSkins = function (a) {
- sa = a
- };
- canvas.setNames = function (a) {
- Q = a
- };
- canvas.setDarkTheme = function (a) {
- ba = a
- };
- canvas.setColors = function (a) {
- da = a
- };
- canvas.setShowMass = function (a) {
- ta = a
- };
- canvas.connect = openSocket;
- var qa = -1
- , ra = -1
- , leaderBoardCanvas = null
- , w = 1
- , O = null
- , R = {}
- , skins = "poland;usa;china;russia;canada;australia;spain;brazil;germany;ukraine;france;sweden;hitler;north korea;south korea;japan;united kingdom;earth;greece;latvia;lithuania;estonia;finland;norway;cia;maldivas;austria;nigeria;reddit;yaranaika;confederate;9gag;indiana;4chan;italy;ussr;pewdiepie;bulgaria;tumblr;2ch.hk;hong kong;portugal;jamaica;german empire;mexico;sanik;switzerland;croatia;chile;indonesia;bangladesh;thailand;iran;iraq;peru;moon;botswana;bosnia;netherlands;european union;taiwan;pakistan;hungary;satanist;qing dynasty;nazi;matriarchy;patriarchy;feminism;ireland;texas;facepunch;prodota;cambodia;steam;piccolo;ea;india;kc;denmark;quebec;ayy lmao;sealand;bait;tsarist russia;origin;vinesauce;stalin;belgium;luxembourg;stussy;prussia;8ch;argentina;scotland;sir;romania;belarus;wojak;isis;doge".split(";")
- , Fa = ["m'blob"];
- createCircle.prototype = {
- id: 0
- , points: null
- , pointsAcc: null
- , name: null
- , nameCache: null
- , sizeCache: null
- , x: 0
- , y: 0
- , size: 0
- , ox: 0
- , oy: 0
- , oSize: 0
- , nx: 0
- , ny: 0
- , nSize: 0
- , updateTime: 0
- , updateCode: 0
- , drawTime: 0
- , destroyed: !1
- , isVirus: !1
- , destroy: function () {
- var a;
- for (a = 0; a < circleArray.length; a++)
- if (circleArray[a] == this) {
- circleArray.splice(a, 1);
- break
- }
- delete z[this.id];
- a = myCircles.indexOf(this); - 1 != a && (aa = !0, myCircles.splice(a, 1));
- a = D.indexOf(this.id); - 1 != a && D.splice(a, 1);
- this.destroyed = !0;
- E.push(this)
- }
- , getNameSize: function () {
- return Math.max(~~(.3 * this.size), 24)
- }
- , setName: function (a) {
- if (this.name = a) null == this.nameCache ? this.nameCache = new P(this.getNameSize(), "#FFFFFF", !0, "#000000") : this.nameCache.setSize(this.getNameSize()), this.nameCache.setValue(this.name)
- }
- , createPoints: function () {
- for (var a = this.getNumPoints(); this.points.length > a;) {
- var b = ~~(Math.random() * this.points.length);
- this.points.splice(b, 1);
- this.pointsAcc.splice(b, 1)
- }
- 0 == this.points.length && 0 < a && (this.points.push({
- c: this
- , v: this.size
- , x: this.x
- , y: this.y
- }), this.pointsAcc.push(Math.random() - .5));
- for (; this.points.length < a;) {
- var b = ~~(Math.random() * this.points.length)
- , c = this.points[b];
- this.points.splice(b, 0, {
- c: this
- , v: c.v
- , x: c.x
- , y: c.y
- });
- this.pointsAcc.splice(b, 0, this.pointsAcc[b])
- }
- }
- , getNumPoints: function () {
- return ~~Math.max(this.size * zoom * (this.isVirus ? Math.min(2 * w, 1) : w), this.isVirus ? 10 : 5)
- }
- , movePoints: function () {
- this.createPoints();
- for (var a = this.points, b = this.pointsAcc, c = b.concat(), d = a.concat(), g = d.length, e = 0; e < g; ++e) {
- var h = c[(e - 1 + g) % g]
- , l = c[(e + 1) % g];
- b[e] += Math.random() - .5;
- b[e] *= .7;
- 10 < b[e] && (b[e] = 10); - 10 > b[e] && (b[e] = -10);
- b[e] = (h + l + 8 * b[e]) / 10
- }
- for (var n =
- this, e = 0; e < g; ++e) {
- c = d[e].v;
- h = d[(e - 1 + g) % g].v;
- l = d[(e + 1) % g].v;
- if (15 < this.size) {
- var m = !1
- , k = a[e].x
- , p = a[e].y;
- quadTree.retrieve2(k - 5, p - 5, 10, 10, function (a) {
- a.c != n && 25 > (k - a.x) * (k - a.x) + (p - a.y) * (p - a.y) && (m = !0)
- });
- !m && (a[e].x < X || a[e].y < Y || a[e].x > Z || a[e].y > $) && (m = !0);
- m && (0 < b[e] && (b[e] = 0), b[e] -= 1)
- }
- c += b[e];
- 0 > c && (c = 0);
- c = (12 * c + this.size) / 13;
- a[e].v = (h + l + 8 * c) / 10;
- h = 2 * Math.PI / g;
- l = this.points[e].v;
- this.isVirus && 0 == e % 2 && (l += 5);
- a[e].x = this.x + Math.cos(h * e) * l;
- a[e].y = this.y + Math.sin(h * e) * l
- }
- }
- , updatePos: function () {
- var a;
- a = (F - this.updateTime) /
- 120;
- a = 0 > a ? 0 : 1 < a ? 1 : a;
- a = a * a * (3 - 2 * a);
- var b = this.getNameSize();
- if (this.destroyed && 1 <= a) {
- var c = E.indexOf(this); - 1 != c && E.splice(c, 1)
- }
- this.x = a * (this.nx - this.ox) + this.ox;
- this.y = a * (this.ny - this.oy) + this.oy;
- this.size = a * (this.nSize - this.oSize) + this.oSize;
- this.destroyed || b == this.getNameSize() || this.setName(this.name);
- return a
- }
- , shouldRender: function () {
- return this.x + this.size + 40 < x - width / 2 / zoom || this.y + this.size + 40 < y - height / 2 / zoom || this.x - this.size - 40 > x + width / 2 / zoom || this.y - this.size - 40 > y + height / 2 / zoom ? !1 : !0
- }
- , draw: function () {
- if (this.shouldRender()) {
- ctx.save();
- this.drawTime = F;
- var a = this.updatePos();
- this.destroyed && (ctx.globalAlpha *= 1 - a);
- this.movePoints();
- da ? (ctx.fillStyle = "#FFFFFF", ctx.strokeStyle = "#AAAAAA") : (ctx.fillStyle = this.color, ctx.strokeStyle = this.color);
- ctx.beginPath();
- ctx.lineWidth = 10;
- ctx.lineCap = "round";
- ctx.lineJoin = this.isVirus ? "mitter" : "round";
- a = this.getNumPoints();
- ctx.moveTo(this.points[0].x, this.points[0].y);
- for (var b = 1; b <= a; ++b) {
- var c = b % a;
- ctx.lineTo(this.points[c].x, this.points[c].y)
- }
- ctx.closePath();
- a = this.name.toLowerCase();
- sa ? -1 != skins.indexOf(a) ? (R.hasOwnProperty(a) || (R[a] = new Image, R[a].src = "skins/" + a + ".png"), b = R[a]) : b = null : b = null;
- a = b ? -1 != Fa.indexOf(a) : !1;
- ctx.stroke();
- ctx.fill();
- null != b && 0 < b.width && !a && (ctx.save(), ctx.clip(), ctx.drawImage(b, this.x - this.size, this.y - this.size, 2 * this.size, 2 * this.size), ctx.restore());
- if (da || 15 < this.size) ctx.strokeStyle = "#000000", ctx.globalAlpha *= .1, ctx.stroke();
- ctx.globalAlpha = 1;
- null != b && 0 < b.width && a && ctx.drawImage(b, this.x - 2 * this.size, this.y - 2 * this.size, 4 * this.size, 4 * this.size);
- a = -1 != myCircles.indexOf(this);
- b = ~~this.y;
- (Q || a) && this.name && this.nameCache && (c = this.nameCache.render(), ctx.drawImage(c, ~~this.x - ~~(c.width / 2), b - ~~(c.height / 2)), b += c.height / 2 + 4);
- ta && a && (null == this.sizeCache && (this.sizeCache = new P(this.getNameSize() / 2, "#FFFFFF", !0, "#000000")), this.sizeCache.setSize(this.getNameSize() / 2), this.sizeCache.setValue(~~(this.size * this.size / 100)), c = this.sizeCache.render(), ctx.drawImage(c, ~~this.x - ~~(c.width / 2), b - ~~(c.height / 2)));
- ctx.restore()
- }
- }
- };
- P.prototype = {
- _value: ""
- , _color: "#000000"
- , _stroke: !1
- , _strokeColor: "#000000"
- , _size: 16
- , _canvas: null
- , _ctx: null
- , _dirty: !1
- , setSize: function (a) {
- this._size !=
- a && (this._size = a, this._dirty = !0)
- }
- , setColor: function (a) {
- this._color != a && (this._color = a, this._dirty = !0)
- }
- , setStroke: function (a) {
- this._stroke != a && (this._stroke = a, this._dirty = !0)
- }
- , setStrokeColor: function (a) {
- this._strokeColor != a && (this._strokeColor = a, this._dirty = !0)
- }
- , setValue: function (a) {
- a != this._value && (this._value = a, this._dirty = !0)
- }
- , render: function () {
- null == this._canvas && (this._canvas = document.createElement("canvas"), this._ctx = this._canvas.getContext("2d"));
- if (this._dirty) {
- var a = this._canvas
- , b = this._ctx
- , c = this._value
- , d = this._size
- , g = d + "px Ubuntu";
- b.font = g;
- var e = b.measureText(c)
- .width
- , h = ~~(.2 * d);
- a.width = e + 6;
- a.height = d + h;
- b.font = g;
- b.globalAlpha = 1;
- b.lineWidth = 3;
- b.strokeStyle = this._strokeColor;
- b.fillStyle = this._color;
- this._stroke && b.strokeText(c, 3, d - h / 2);
- b.fillText(c, 3, d - h / 2)
- }
- return this._canvas
- }
- };
- canvas.onload = onload
- }
- })(window, jQuery);
Add Comment
Please, Sign In to add comment