sobinist

Untitled

May 5th, 2015
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.39 KB | None | 0 0
  1. (function (canvas, v) {
  2. function onload() {
  3. retrieveRegions();
  4. setInterval(retrieveRegions, 18E4);
  5. B = S = document.getElementById("canvas");
  6. ctx = B.getContext("2d");
  7. B.onmousedown = function (a) {
  8. if (fa) {
  9. var b = a.clientX - (5 + width / 5 / 2)
  10. , c = a.clientY - (5 + width / 5 / 2);
  11. if (Math.sqrt(b * b + c * c) <= width / 5 / 2) {
  12. G();
  13. networkSendCharlie(17);
  14. return
  15. }
  16. }
  17. J = a.clientX;
  18. K = a.clientY;
  19. interpolate();
  20. G()
  21. };
  22. B.onmousemove = function (a) {
  23. J = a.clientX;
  24. K = a.clientY;
  25. interpolate()
  26. };
  27. B.onmouseup = function (a) {};
  28. var a = !1
  29. , b = !1
  30. , c = !1;
  31. canvas.onkeydown = function (f) {
  32. 32 != f.keyCode || a || (G(), networkSendCharlie(17), a = !0);
  33. 81 != f.keyCode || b || (networkSendCharlie(18), b = !0);
  34. 87 != f.keyCode || c || (G(), networkSendCharlie(21), c = !0)
  35. };
  36. canvas.onkeyup = function (f) {
  37. 32 == f.keyCode && (a = !1);
  38. 87 == f.keyCode && (c = !1);
  39. 81 == f.keyCode && b && (networkSendCharlie(19), b = !1)
  40. };
  41. canvas.onblur = function () {
  42. networkSendCharlie(19);
  43. c = b = a = !1
  44. };
  45. canvas.onresize = onWindowUpdate;
  46. onWindowUpdate();
  47. canvas.requestAnimationFrame ? canvas.requestAnimationFrame(renderLoop) : setInterval(render, 1E3 / 60);
  48. setInterval(G, 100);
  49. ia(v("#region")
  50. .val())
  51. }
  52.  
  53. // something to do with quadtrees
  54. function addCirclesToQuadTree() {
  55. 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);
  56. quadTree = QUAD.init({
  57. minX: a - (d + 100)
  58. , minY: b - (d + 100)
  59. , maxX: c + (d + 100)
  60. , maxY: f + (d + 100)
  61. });
  62. for (e = 0; e < circleArray.length; e++)
  63. if (a = circleArray[e], a.shouldRender())
  64. for (b = 0; b < a.points.length; ++b) quadTree.insert(a.points[b])
  65. }
  66.  
  67. // interpolation?
  68. function interpolate() {
  69. L = (J - width / 2) / zoom + x;
  70. M = (K - height / 2) / zoom + y
  71. }
  72.  
  73. function retrieveRegions() {
  74. N == null && (N = {}, v("#region")
  75. .children()
  76. .each(function () {
  77. var a = v(this)
  78. , b = a.val();
  79. b && (N[b] = a.text())
  80. }));
  81. v.get("http://m.agar.io/info", function (a) {
  82. for (var b in a.regions) v('#region option[value="' + b + '"]')
  83. .text(N[b] + " (" + a.regions[b].numPlayers + " players)")
  84. }
  85. , "json")
  86. }
  87.  
  88. function ia(a) {
  89. a && a != W && (W = a, startConnect())
  90. }
  91.  
  92. function tryConnect() {
  93. v.ajax("http://m.agar.io/", {
  94. error: function () {
  95. setTimeout(tryConnect, 1E3)
  96. }
  97. , success: function (a) {
  98. a = a.split("\n");
  99. openSocket("ws://" + a[0])
  100. }
  101. , dataType: "text"
  102. , method: "POST"
  103. , cache: !1
  104. , crossDomain: !0
  105. , data: W || "?"
  106. })
  107. }
  108.  
  109. function startConnect() {
  110. v("#connecting")
  111. .show();
  112. tryConnect()
  113. }
  114.  
  115. function openSocket(address) {
  116. hSocket && (hSocket.onopen = null, hSocket.onmessage = null, hSocket.onclose = null, hSocket.close(), hSocket = null);
  117. D = [];
  118. myCircles = [];
  119. z = {};
  120. circleArray = [];
  121. E = [];
  122. q = [];
  123. console.log("Connecting to " + address);
  124. hSocket = new WebSocket(address);
  125. hSocket.binaryType = "arraybuffer";
  126. hSocket.onopen = wa;
  127. hSocket.onmessage = xa;
  128. hSocket.onclose = onSocketClose;
  129. hSocket.onerror = function () {
  130. console.log("socket error")
  131. }
  132. }
  133.  
  134. function wa(a) {
  135. v("#connecting")
  136. .hide();
  137. console.log("socket open");
  138. a = new ArrayBuffer(5);
  139. var b = new DataView(a);
  140. b.setUint8(0, 255);
  141. b.setUint32(1, 1, !0);
  142. hSocket.send(a);
  143. sendHandshake()
  144. }
  145.  
  146. function onSocketClose(a) {
  147. console.log("socket close");
  148. setTimeout(startConnect, 500)
  149. }
  150.  
  151. function xa(a) {
  152. function b() {
  153. for (var a = "";;) {
  154. var b = f.getUint16(c, !0);
  155. c += 2;
  156. if (0 == b) break;
  157. a += String.fromCharCode(b)
  158. }
  159. return a
  160. }
  161. var c = 1
  162. , f = new DataView(a.data);
  163. switch (f.getUint8(0)) {
  164. case 16:
  165. za(f);
  166. break;
  167. case 20:
  168. myCircles = [];
  169. D = [];
  170. break;
  171. case 32:
  172. D.push(f.getUint32(1, !0));
  173. break;
  174. case 48:
  175. for (q = []; c < f.byteLength;) q.push(b());
  176. drawLeaderboard();
  177. break;
  178. case 49:
  179. a = f.getUint32(c, !0);
  180. c += 4;
  181. q = [];
  182. for (var d = 0; d < a; ++d) f.getUint32(c, !0), c += 4, q.push(b());
  183. drawLeaderboard();
  184. break;
  185. case 64:
  186. 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)
  187. }
  188. }
  189.  
  190. function za(a) {
  191. F = +new Date;
  192. var b = Math.random()
  193. , c = 1;
  194. aa = !1;
  195. for (var f = a.getUint16(c, !0), c = c + 2, d = 0; d < f; ++d) {
  196. var e = z[a.getUint32(c, !0)]
  197. , t = z[a.getUint32(c + 4, !0)]
  198. , c = c + 8;
  199. e &&
  200. 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)
  201. }
  202. for (;;) {
  203. f = a.getUint32(c, !0);
  204. c += 4;
  205. if (0 == f) break;
  206. var d = a.getFloat64(c, !0)
  207. , c = c + 8
  208. , e = a.getFloat64(c, !0)
  209. , c = c + 8
  210. , t = a.getFloat64(c, !0)
  211. , c = c + 8
  212. , l = a.getUint8(c++)
  213. , h = !1;
  214. if (0 == l) h = !0, l = "#33FF33";
  215. else if (255 == l) {
  216. var h = a.getUint8(c++)
  217. , l = a.getUint8(c++)
  218. , g = a.getUint8(c++)
  219. , l = oa(h << 16 | l << 8 | g)
  220. , g = a.getUint8(c++)
  221. , h = !!(g & 1);
  222. g & 2 && (c += 4);
  223. g & 4 && (c += 8);
  224. g & 8 && (c += 16)
  225. } else {
  226. var l = 63487 | l << 16
  227. , k = (l >> 16 & 255) / 255 * 360
  228. , n = (l >> 8 & 255) / 255
  229. , l = (l >>
  230. 0 & 255) / 255;
  231. if (0 == n) l = l << 16 | l << 8 | l << 0;
  232. else {
  233. var k = k / 60
  234. , g = ~~k
  235. , u = k - g
  236. , k = l * (1 - n)
  237. , s = l * (1 - n * u)
  238. , n = l * (1 - n * (1 - u))
  239. , p = u = 0
  240. , q = 0;
  241. switch (g % 6) {
  242. case 0:
  243. u = l;
  244. p = n;
  245. q = k;
  246. break;
  247. case 1:
  248. u = s;
  249. p = l;
  250. q = k;
  251. break;
  252. case 2:
  253. u = k;
  254. p = l;
  255. q = n;
  256. break;
  257. case 3:
  258. u = k;
  259. p = s;
  260. q = l;
  261. break;
  262. case 4:
  263. u = n;
  264. p = k;
  265. q = l;
  266. break;
  267. case 5:
  268. u = l, p = k, q = s
  269. }
  270. u = ~~(255 * u) & 255;
  271. p = ~~(255 * p) & 255;
  272. q = ~~(255 * q) & 255;
  273. l = u << 16 | p << 8 | q
  274. }
  275. l = oa(l)
  276. }
  277. for (g = "";;) {
  278. k = a.getUint16(c, !0);
  279. c += 2;
  280. if (0 == k) break;
  281. g += String.fromCharCode(k)
  282. }
  283. k = null;
  284. z.hasOwnProperty(f) ? (k = z[f], k.updatePos(), k.ox = k.x, k.oy = k.y, k.oSize = k.size, k.color =
  285. l) : (k = new createCircle(f, d, e, t, l, h, g), k.pX = d, k.pY = e);
  286. k.nx = d;
  287. k.ny = e;
  288. k.nSize = t;
  289. k.updateCode = b;
  290. k.updateTime = F; - 1 != D.indexOf(f) && -1 == myCircles.indexOf(k) && (document.getElementById("overlays")
  291. .style.display = "none", myCircles.push(k), 1 == myCircles.length && (x = k.x, y = k.y))
  292. }
  293. a.getUint16(c, !0);
  294. c += 2;
  295. e = a.getUint32(c, !0);
  296. c += 4;
  297. for (d = 0; d < e; d++) f = a.getUint32(c, !0), c += 4, z[f] && (z[f].updateCode = b);
  298. for (d = 0; d < circleArray.length; d++) circleArray[d].updateCode != b && circleArray[d--].destroy();
  299. aa && 0 == myCircles.length && v("#overlays")
  300. .fadeIn(3E3)
  301. }
  302.  
  303. function G() {
  304. if (null != hSocket && hSocket.readyState == hSocket.OPEN) {
  305. var a = J - width / 2
  306. , b = K - height / 2;
  307. 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))
  308. }
  309. }
  310.  
  311. // send handshake (??)
  312. function sendHandshake() {
  313. if (null != hSocket && hSocket.readyState == hSocket.OPEN && null != HArray) {
  314. var arrayBuffer = new ArrayBuffer(1 + 2 * HArray.length)
  315. , bufferDataView = new DataView(arrayBuffer);
  316. bufferDataView.setUint8(0, 0);
  317. for (var c = 0; c < HArray.length; ++c) bufferDataView.setUint16(1 + 2 * c, HArray.charCodeAt(c), !0);
  318. hSocket.send(arrayBuffer)
  319. }
  320. }
  321.  
  322. // don't know what this does, sends one UInt8
  323. function networkSendCharlie(a) {
  324. if (null != hSocket && hSocket.readyState == hSocket.OPEN) {
  325. var b = new ArrayBuffer(1);
  326. (new DataView(b))
  327. .setUint8(0, a);
  328. hSocket.send(b)
  329. }
  330. }
  331.  
  332. function renderLoop() {
  333. render();
  334. canvas.requestAnimationFrame(renderLoop)
  335. }
  336.  
  337. // on window update?
  338. function onWindowUpdate() {
  339. width = canvas.innerWidth;
  340. height = canvas.innerHeight;
  341. S.width = B.width = width;
  342. S.height = B.height = height;
  343. render()
  344. }
  345.  
  346. function calculateZoom() {
  347. // myCircles (probably) stores the circles the player controls
  348. if (0 != myCircles.length) {
  349. for (var a = 0, b = 0; b < myCircles.length; b++) a += myCircles[b].size;
  350. a = Math.pow(Math.min(64 / a, 1), .4) * Math.max(height / 965, width / 1920);
  351. zoom = (9 * zoom + a) / 10
  352. }
  353. }
  354.  
  355. function render() {
  356. var a = +new Date;
  357. ++Ba;
  358. calculateZoom();
  359. F = +new Date;
  360.  
  361. // draw update circles
  362. if (0 < myCircles.length) {
  363. 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;
  364. x = (x + b) / 2;
  365. y = (y + c) / 2
  366. }
  367. addCirclesToQuadTree();
  368. interpolate();
  369. ctx.clearRect(0, 0, width, height);
  370. ctx.fillStyle = ba ? "#111111" :
  371. "#F2FBFF";
  372. ctx.fillRect(0, 0, width, height);
  373. ctx.save();
  374. ctx.strokeStyle = ba ? "#AAAAAA" : "#000000";
  375. ctx.globalAlpha = .2;
  376. ctx.scale(zoom, zoom);
  377. b = width / zoom;
  378. c = height / zoom;
  379. for (f = -.5 + (-x + b / 2) % 50; f < b; f += 50) ctx.beginPath(), ctx.moveTo(f, 0), ctx.lineTo(f, c), ctx.stroke();
  380. for (f = -.5 + (-y + c / 2) % 50; f < c; f += 50) ctx.beginPath(), ctx.moveTo(0, f), ctx.lineTo(b, f), ctx.stroke();
  381. ctx.restore();
  382. circleArray.sort(function (circleA, circleB) {
  383. return circleA.size == circleB.size ? circleA.id - circleB.id : circleA.size - circleB.size
  384. });
  385. ctx.save();
  386. ctx.translate(width / 2, height / 2);
  387. ctx.scale(zoom, zoom);
  388. ctx.translate(-x, -y);
  389. for (f = 0; f < E.length; f++) E[f].draw();
  390. for (f = 0; f < circleArray.length; f++) circleArray[f].draw();
  391. ctx.restore();
  392. leaderBoardCanvas && 0 != q.length && ctx.drawImage(leaderBoardCanvas, width - leaderBoardCanvas.width - 10, 10);
  393. I = Math.max(I, calculateScore());
  394. 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));
  395. Da();
  396. a = +new Date - a;
  397. a > 1E3 / 60 ? w -= .01 : a < 1E3 / 65 && (w += .01);.4 > w && (w = .4);
  398. 1 < w && (w = 1)
  399. }
  400.  
  401. function Da() {
  402. if (fa && ca.width) {
  403. var a = width / 5;
  404. ctx.drawImage(ca, 5, 5, a, a)
  405. }
  406. }
  407.  
  408. // calculate the score for the circles owned by the player
  409. function calculateScore() {
  410. for (var a = 0, b = 0; b < myCircles.length; b++) {
  411. a += myCircles[b].nSize * myCircles[b].nSize;
  412. }
  413. return a
  414. }
  415.  
  416. function drawLeaderboard() {
  417. if (0 != q.length)
  418. if (Q) {
  419. leaderBoardCanvas = document.createElement("canvas");
  420. var lCtx = leaderBoardCanvas.getContext("2d")
  421. , b = 60 + 24 * q.length
  422. , c = Math.min(200, .3 * width) / 200;
  423. leaderBoardCanvas.width = 200 * c;
  424. leaderBoardCanvas.height = b * c;
  425. lCtx.scale(c, c);
  426. lCtx.globalAlpha = .4;
  427. lCtx.fillStyle = "#000000";
  428. lCtx.fillRect(0, 0, 200, b);
  429. lCtx.globalAlpha = 1;
  430. lCtx.fillStyle = "#FFFFFF";
  431. c = null;
  432. c = "Leaderboard";
  433. lCtx.font = "30px Ubuntu";
  434. lCtx.fillText(c, 100 - lCtx.measureText(c)
  435. .width / 2, 40);
  436. lCtx.font = "20px Ubuntu";
  437. 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 +
  438. 1 + ". " + c, lCtx.fillText(c, 100 - lCtx.measureText(c)
  439. .width / 2, 70 + 24 * b)
  440. } else leaderBoardCanvas = null
  441. }
  442.  
  443. function createCircle(id, ox, oy, size, color, virus, name) {
  444. circleArray.push(this);
  445. z[id] = this;
  446. this.id = id;
  447. this.ox = this.x = ox;
  448. this.oy = this.y = oy;
  449. this.oSize = this.size = size;
  450. this.color = color;
  451. this.isVirus = virus;
  452. this.points = [];
  453. this.pointsAcc = [];
  454. this.createPoints();
  455. this.setName(name)
  456. }
  457.  
  458. function oa(a) {
  459. for (a = a.toString(16); a.length < 6;) a = "0" + a;
  460. return "#" + a
  461. }
  462.  
  463. function P(a, b, c, d) {
  464. a && (this._size = a);
  465. b && (this._color = b);
  466. this._stroke = !!c;
  467. d && (this._strokeColor = d)
  468. }
  469.  
  470. if ("agar.io" != canvas.location.hostname && "localhost" != canvas.location.hostname && "10.10.2.13" != canvas.location.hostname) {
  471. canvas.location = "http://agar.io/";
  472. } else {
  473. var S, ctx, B, width, height, quadTree = null
  474. , hSocket = null
  475. , x = 0
  476. , y = 0
  477. , D = []
  478. , myCircles = []
  479. , z = {}
  480. , circleArray = []
  481. , E = []
  482. , q = []
  483. , J = 0
  484. , K = 0
  485. , L = -1
  486. , M = -1
  487. , Ba = 0
  488. , F = 0
  489. , HArray = null
  490. , X = 0
  491. , Y = 0
  492. , Z = 1E4
  493. , $ = 1E4
  494. , zoom = 1
  495. , W = null
  496. , sa = !0
  497. , Q = !0
  498. , da = !1
  499. , aa = !1
  500. , I = 0
  501. , ba = !1
  502. , ta = !1
  503. , fa = "ontouchstart" in canvas && /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
  504. , ca = new Image;
  505. ca.src = "img/split.png";
  506. var N = null;
  507. canvas.setNick = function (a) {
  508. v("#adsBottom")
  509. .hide();
  510. HArray = a;
  511. sendHandshake();
  512. v("#overlays")
  513. .hide();
  514. I = 0
  515. };
  516. canvas.setRegion = ia;
  517. canvas.setSkins = function (a) {
  518. sa = a
  519. };
  520. canvas.setNames = function (a) {
  521. Q = a
  522. };
  523. canvas.setDarkTheme = function (a) {
  524. ba = a
  525. };
  526. canvas.setColors = function (a) {
  527. da = a
  528. };
  529. canvas.setShowMass = function (a) {
  530. ta = a
  531. };
  532. canvas.connect = openSocket;
  533. var qa = -1
  534. , ra = -1
  535. , leaderBoardCanvas = null
  536. , w = 1
  537. , O = null
  538. , R = {}
  539. , 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(";")
  540. , Fa = ["m'blob"];
  541. createCircle.prototype = {
  542. id: 0
  543. , points: null
  544. , pointsAcc: null
  545. , name: null
  546. , nameCache: null
  547. , sizeCache: null
  548. , x: 0
  549. , y: 0
  550. , size: 0
  551. , ox: 0
  552. , oy: 0
  553. , oSize: 0
  554. , nx: 0
  555. , ny: 0
  556. , nSize: 0
  557. , updateTime: 0
  558. , updateCode: 0
  559. , drawTime: 0
  560. , destroyed: !1
  561. , isVirus: !1
  562. , destroy: function () {
  563. var a;
  564. for (a = 0; a < circleArray.length; a++)
  565. if (circleArray[a] == this) {
  566. circleArray.splice(a, 1);
  567. break
  568. }
  569. delete z[this.id];
  570. a = myCircles.indexOf(this); - 1 != a && (aa = !0, myCircles.splice(a, 1));
  571. a = D.indexOf(this.id); - 1 != a && D.splice(a, 1);
  572. this.destroyed = !0;
  573. E.push(this)
  574. }
  575. , getNameSize: function () {
  576. return Math.max(~~(.3 * this.size), 24)
  577. }
  578. , setName: function (a) {
  579. 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)
  580. }
  581. , createPoints: function () {
  582. for (var a = this.getNumPoints(); this.points.length > a;) {
  583. var b = ~~(Math.random() * this.points.length);
  584. this.points.splice(b, 1);
  585. this.pointsAcc.splice(b, 1)
  586. }
  587. 0 == this.points.length && 0 < a && (this.points.push({
  588. c: this
  589. , v: this.size
  590. , x: this.x
  591. , y: this.y
  592. }), this.pointsAcc.push(Math.random() - .5));
  593. for (; this.points.length < a;) {
  594. var b = ~~(Math.random() * this.points.length)
  595. , c = this.points[b];
  596. this.points.splice(b, 0, {
  597. c: this
  598. , v: c.v
  599. , x: c.x
  600. , y: c.y
  601. });
  602. this.pointsAcc.splice(b, 0, this.pointsAcc[b])
  603. }
  604. }
  605. , getNumPoints: function () {
  606. return ~~Math.max(this.size * zoom * (this.isVirus ? Math.min(2 * w, 1) : w), this.isVirus ? 10 : 5)
  607. }
  608. , movePoints: function () {
  609. this.createPoints();
  610. for (var a = this.points, b = this.pointsAcc, c = b.concat(), d = a.concat(), g = d.length, e = 0; e < g; ++e) {
  611. var h = c[(e - 1 + g) % g]
  612. , l = c[(e + 1) % g];
  613. b[e] += Math.random() - .5;
  614. b[e] *= .7;
  615. 10 < b[e] && (b[e] = 10); - 10 > b[e] && (b[e] = -10);
  616. b[e] = (h + l + 8 * b[e]) / 10
  617. }
  618. for (var n =
  619. this, e = 0; e < g; ++e) {
  620. c = d[e].v;
  621. h = d[(e - 1 + g) % g].v;
  622. l = d[(e + 1) % g].v;
  623. if (15 < this.size) {
  624. var m = !1
  625. , k = a[e].x
  626. , p = a[e].y;
  627. quadTree.retrieve2(k - 5, p - 5, 10, 10, function (a) {
  628. a.c != n && 25 > (k - a.x) * (k - a.x) + (p - a.y) * (p - a.y) && (m = !0)
  629. });
  630. !m && (a[e].x < X || a[e].y < Y || a[e].x > Z || a[e].y > $) && (m = !0);
  631. m && (0 < b[e] && (b[e] = 0), b[e] -= 1)
  632. }
  633. c += b[e];
  634. 0 > c && (c = 0);
  635. c = (12 * c + this.size) / 13;
  636. a[e].v = (h + l + 8 * c) / 10;
  637. h = 2 * Math.PI / g;
  638. l = this.points[e].v;
  639. this.isVirus && 0 == e % 2 && (l += 5);
  640. a[e].x = this.x + Math.cos(h * e) * l;
  641. a[e].y = this.y + Math.sin(h * e) * l
  642. }
  643. }
  644. , updatePos: function () {
  645. var a;
  646. a = (F - this.updateTime) /
  647. 120;
  648. a = 0 > a ? 0 : 1 < a ? 1 : a;
  649. a = a * a * (3 - 2 * a);
  650. var b = this.getNameSize();
  651. if (this.destroyed && 1 <= a) {
  652. var c = E.indexOf(this); - 1 != c && E.splice(c, 1)
  653. }
  654. this.x = a * (this.nx - this.ox) + this.ox;
  655. this.y = a * (this.ny - this.oy) + this.oy;
  656. this.size = a * (this.nSize - this.oSize) + this.oSize;
  657. this.destroyed || b == this.getNameSize() || this.setName(this.name);
  658. return a
  659. }
  660. , shouldRender: function () {
  661. 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
  662. }
  663. , draw: function () {
  664. if (this.shouldRender()) {
  665. ctx.save();
  666. this.drawTime = F;
  667. var a = this.updatePos();
  668. this.destroyed && (ctx.globalAlpha *= 1 - a);
  669. this.movePoints();
  670. da ? (ctx.fillStyle = "#FFFFFF", ctx.strokeStyle = "#AAAAAA") : (ctx.fillStyle = this.color, ctx.strokeStyle = this.color);
  671. ctx.beginPath();
  672. ctx.lineWidth = 10;
  673. ctx.lineCap = "round";
  674. ctx.lineJoin = this.isVirus ? "mitter" : "round";
  675. a = this.getNumPoints();
  676. ctx.moveTo(this.points[0].x, this.points[0].y);
  677. for (var b = 1; b <= a; ++b) {
  678. var c = b % a;
  679. ctx.lineTo(this.points[c].x, this.points[c].y)
  680. }
  681. ctx.closePath();
  682. a = this.name.toLowerCase();
  683. 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;
  684. a = b ? -1 != Fa.indexOf(a) : !1;
  685. ctx.stroke();
  686. ctx.fill();
  687. 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());
  688. if (da || 15 < this.size) ctx.strokeStyle = "#000000", ctx.globalAlpha *= .1, ctx.stroke();
  689. ctx.globalAlpha = 1;
  690. 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);
  691. a = -1 != myCircles.indexOf(this);
  692. b = ~~this.y;
  693. (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);
  694. 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)));
  695. ctx.restore()
  696. }
  697. }
  698. };
  699. P.prototype = {
  700. _value: ""
  701. , _color: "#000000"
  702. , _stroke: !1
  703. , _strokeColor: "#000000"
  704. , _size: 16
  705. , _canvas: null
  706. , _ctx: null
  707. , _dirty: !1
  708. , setSize: function (a) {
  709. this._size !=
  710. a && (this._size = a, this._dirty = !0)
  711. }
  712. , setColor: function (a) {
  713. this._color != a && (this._color = a, this._dirty = !0)
  714. }
  715. , setStroke: function (a) {
  716. this._stroke != a && (this._stroke = a, this._dirty = !0)
  717. }
  718. , setStrokeColor: function (a) {
  719. this._strokeColor != a && (this._strokeColor = a, this._dirty = !0)
  720. }
  721. , setValue: function (a) {
  722. a != this._value && (this._value = a, this._dirty = !0)
  723. }
  724. , render: function () {
  725. null == this._canvas && (this._canvas = document.createElement("canvas"), this._ctx = this._canvas.getContext("2d"));
  726. if (this._dirty) {
  727. var a = this._canvas
  728. , b = this._ctx
  729. , c = this._value
  730. , d = this._size
  731. , g = d + "px Ubuntu";
  732. b.font = g;
  733. var e = b.measureText(c)
  734. .width
  735. , h = ~~(.2 * d);
  736. a.width = e + 6;
  737. a.height = d + h;
  738. b.font = g;
  739. b.globalAlpha = 1;
  740. b.lineWidth = 3;
  741. b.strokeStyle = this._strokeColor;
  742. b.fillStyle = this._color;
  743. this._stroke && b.strokeText(c, 3, d - h / 2);
  744. b.fillText(c, 3, d - h / 2)
  745. }
  746. return this._canvas
  747. }
  748. };
  749. canvas.onload = onload
  750. }
  751. })(window, jQuery);
Add Comment
Please, Sign In to add comment