-
-
Save abby-sergz/65aad7682de388f14ee2 to your computer and use it in GitHub Desktop.
Slightly deobfuscated main_out.js for http://agar.io
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(g, v, win, $jq) { | |
function init() { | |
getInfo(); | |
setInterval(getInfo, 18E4); | |
g_canvasElem = document.getElementById("canvas"); | |
g_context2d = d = g_canvasElem.getContext("2d"); | |
g_canvasElem.onmousedown = function(a) { | |
if (isMobile) { | |
var b = a.clientX - (5 + winWidth / 5 / 2), c = a.clientY - (5 + winWidth / 5 / 2); | |
if (Math.sqrt(b * b + c * c) <= winWidth / 5 / 2) { | |
sendMouseCoords(); | |
sendUint8(17); | |
return | |
} | |
} | |
g_mouseX = a.clientX; | |
g_mouseY = a.clientY; | |
updateMouseCoordinates(); | |
sendMouseCoords() | |
}; | |
g_canvasElem.onmousemove = function(a) { | |
g_mouseX = a.clientX; | |
g_mouseY = a.clientY; | |
updateMouseCoordinates() | |
}; | |
g_canvasElem.onmouseup = function(a) { | |
}; | |
var a = false, b = false, c = false; | |
win.onkeydown = function(f) { | |
/*space*/32 != f.keyCode || a || (sendMouseCoords(), sendUint8(17), a = true); | |
/*q*/81 != f.keyCode || b || (sendUint8(18), b = true); | |
/*w*/87 != f.keyCode || c || (sendMouseCoords(), sendUint8(21), c = true) | |
}; | |
win.onkeyup = function(f) { | |
/*space*/32 == f.keyCode && (a = false); | |
/*w*/87 == f.keyCode && (c = false); | |
/*q*/81 == f.keyCode && b && (sendUint8(19), b = false) | |
}; | |
win.onblur = function() { | |
sendUint8(19); | |
c = b = a = false | |
}; | |
win.onresize = onWindowResized; | |
onWindowResized(); | |
win.requestAnimationFrame ? win.requestAnimationFrame(drawStep) : setInterval(draw, 1E3 / 60); | |
setInterval(sendMouseCoords, 100); | |
onRegionChosen($jq("#region").val()) | |
} | |
function va() { | |
// find the leftmost, rightmost, topmost and bottommost coordinate of items (stored in `r`) | |
for (var leftmost = Number.POSITIVE_INFINITY, topmost = Number.POSITIVE_INFINITY, rightmost = Number.NEGATIVE_INFINITY, bottommost = Number.NEGATIVE_INFINITY, d = 0, e = 0; e < g_allItems.length; e++) | |
d = Math.max(g_allItems[e].size, d), leftmost = Math.min(g_allItems[e].x, leftmost), topmost = Math.min(g_allItems[e].y, topmost), rightmost = Math.max(g_allItems[e].x, rightmost), bottommost = Math.max(g_allItems[e].y, bottommost); | |
// initialize QuadTree and extend the area by 100 units in each direction | |
// Why?... | |
g_quadTree = QUAD.init({minX: leftmost - (d + 100),minY: topmost - (d + 100),maxX: rightmost + (d + 100),maxY: bottommost + (d + 100)}); | |
for (e = 0; e < g_allItems.length; e++) | |
if (a = g_allItems[e], a.shouldRender()) | |
for (b = 0; b < a.points.length; ++b) | |
g_quadTree.insert(a.points[b]) | |
} | |
// set g_mouseField* into values in field coordinate system | |
function updateMouseCoordinates() { | |
g_mouseFieldX = (g_mouseX - winWidth / 2) / s + g_viewPortCenterX | |
g_mouseFieldY = (g_mouseY - winHeight / 2) / s + g_viewPortCenterY; | |
//g_mouseFieldX = 200; | |
//g_mouseFieldY = 200; | |
} | |
function getInfo() { | |
null == normalizedRegionTexts && (normalizedRegionTexts = {}, $jq("#region").children().each(function() { | |
var a = $jq(this), b = a.val(); | |
b && (normalizedRegionTexts[b] = a.text()) | |
})); | |
$jq.get("http://m.agar.io/info", function(resp) { | |
for (var region in resp.regions) | |
$jq('#region option[value="' + region + '"]').text(normalizedRegionTexts[region] + " (" + resp.regions[region].numPlayers + " players)") | |
}, | |
"json") | |
} | |
function onRegionChosen(region) { | |
region && region != g_region && (g_region = region, initiateConnecting()) | |
} | |
function getAndConnectToWSServer() { | |
$jq.ajax("http://m.agar.io/", {error: function() { | |
setTimeout(getAndConnectToWSServer, 1E3) | |
},success: function(data) { | |
connectTo("ws://" + data.split("\n")[0]) | |
},dataType: "text",method: "POST",cache: false,crossDomain: true,data: g_region || "?"}) | |
} | |
function initiateConnecting() { | |
$jq("#connecting").show(); | |
getAndConnectToWSServer() | |
} | |
function connectTo(a) { | |
h && (h.onopen = null, h.onmessage = null, h.onclose = null, h.close(), h = null); | |
g_myPartIDs = []; | |
g_myParts = []; | |
g_allItemsIndexedByID = {}; | |
g_allItems = []; | |
E = []; | |
g_leaders = []; | |
console.log("Connecting to " + a); | |
h = new WebSocket(a); | |
h.binaryType = "arraybuffer"; | |
h.onopen = onWebSocketOpened; | |
h.onmessage = onMessageReceived; | |
h.onclose = onSocketClosed; | |
h.onerror = function() { | |
console.log("socket error") | |
} | |
} | |
function onWebSocketOpened(a) { | |
$jq("#connecting").hide(); | |
console.log("socket open"); | |
a = new ArrayBuffer(5); | |
var b = new DataView(a); | |
b.setUint8(0, 255); | |
b.setUint32(1, 1, /*littleEndian*/true); | |
h.send(a); | |
sendNickName() | |
} | |
function onSocketClosed(a) { | |
console.log("socket close"); | |
setTimeout(initiateConnecting, 500) | |
} | |
function onMessageReceived(a) { | |
function readNickName() { | |
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: | |
// server tick | |
onServerTick(f); | |
break; | |
case 20: | |
g_myParts = []; | |
g_myPartIDs = []; | |
break; | |
case 32: | |
g_myPartIDs.push(f.getUint32(1, !0)); | |
break; | |
case 48: | |
for (g_leaders = []; c < f.byteLength; ) | |
g_leaders.push({id: 0,name: readNickName()}); | |
predrawLeaders(); | |
break; | |
case 49: | |
amountOfLeaders = f.getUint32(c, !0); | |
c += 4; | |
g_leaders = []; | |
for (var d = 0; d < amountOfLeaders; ++d) { | |
var e = f.getUint32(c, !0), c = c + 4; | |
g_leaders.push({id: e,name: readNickName()}) | |
} | |
predrawLeaders(); | |
break; | |
case 64: // get field size | |
g_fieldLeft = f.getFloat64(1, !0), g_fieldTop = f.getFloat64(9, !0), g_fieldBottom = f.getFloat64(17, !0), g_fieldRight = f.getFloat64(25, !0), 0 == g_myParts.length && | |
// JIC, g_viewPortCenter is in field coordinate system. | |
(g_viewPortCenterX = (g_fieldRight + g_fieldLeft) / 2, g_viewPortCenterY = (g_fieldBottom + g_fieldTop) / 2); | |
} | |
} | |
function onServerTick(/*DataView*/a) { | |
F = +new Date; | |
var b = Math.random(), /*offset in DataView*/c = 1; | |
g_onePartEaten = false; | |
for (var f = a.getUint16(c, !0), c = c + 2, d = 0; d < f; ++d) { | |
var e = g_allItemsIndexedByID[a.getUint32(c, !0)], t = | |
g_allItemsIndexedByID[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 (; ; ) { | |
itemId = a.getUint32(c, !0); | |
c += 4; | |
if (0 == itemId) | |
break; | |
// `h` and `l` variables denote whether it's a virus and item color respectively | |
// The logic is too optimized, let's leave them without deobfuscating. | |
var itemX = a.getFloat64(c, !0), c = c + 8, itemY = a.getFloat64(c, !0), c = c + 8, itemSize = 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 = toColorHexString(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, m = (l >> 8 & 255) / 255, l = (l >> 0 & 255) / 255; | |
if (0 == m) | |
l = l << 16 | l << 8 | l << 0; | |
else { | |
var k = k / 60, g = ~~k, u = k - g, k = l * (1 - m), s = l * (1 - m * u), m = l * (1 - m * (1 - u)), p = u = 0, q = 0; | |
switch (g % 6) { | |
case 0: | |
u = l; | |
p = m; | |
q = k; | |
break; | |
case 1: | |
u = s; | |
p = l; | |
q = k; | |
break; | |
case 2: | |
u = k; | |
p = l; | |
q = m; | |
break; | |
case 3: | |
u = k; | |
p = s; | |
q = l; | |
break; | |
case 4: | |
u = m; | |
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 = toColorHexString(l) | |
} | |
for (itemName = ""; ; ) { | |
k = a.getUint16(c, !0); | |
c += 2; | |
if (0 == k) | |
break; | |
itemName += String.fromCharCode(k) | |
} | |
k = null; | |
g_allItemsIndexedByID.hasOwnProperty(itemId) ? (k = g_allItemsIndexedByID[itemId], k.updatePos(), k.ox = | |
k.x, k.oy = k.y, k.oSize = k.size, k.color = l) : (k = new Item(itemId, itemX, itemY, itemSize, l, h, itemName), k.pX = itemX, k.pY = itemY); | |
k.nx = itemX; | |
k.ny = itemY; | |
k.nSize = itemSize; | |
k.updateCode = b; | |
k.updateTime = F; | |
-1 != g_myPartIDs.indexOf(itemId) && -1 == g_myParts.indexOf(k) && (document.getElementById("overlays").style.display = "none", g_myParts.push(k), 1 == g_myParts.length && (g_viewPortCenterX = k.x, g_viewPortCenterY = k.y)) | |
} | |
a.getUint16(c, !0); | |
c += 2; | |
e = a.getUint32(c, !0); | |
c += 4; | |
for (d = 0; d < e; d++) | |
itemId = a.getUint32(c, !0), c += 4, g_allItemsIndexedByID[itemId] && (g_allItemsIndexedByID[itemId].updateCode = b); | |
for (d = 0; d < g_allItems.length; d++) | |
g_allItems[d].updateCode != b && g_allItems[d--].destroy(); | |
g_onePartEaten && 0 == g_myParts.length && v("#overlays").fadeIn(3E3) | |
} | |
function sendMouseCoords() { | |
if (null != h && h.readyState == h.OPEN) { | |
//var a = g_mouseX - winWidth / 2, b = g_mouseY - winHeight / 2; | |
//64 > a * a + b * b || | |
var a, b; | |
//qa == g_mouseFieldX && ra == g_mouseFieldY || | |
(qa = g_mouseFieldX, ra = g_mouseFieldY, a = new ArrayBuffer(21), b = new DataView(a), b.setUint8(0, 16), b.setFloat64(1, g_mouseFieldX, !0), b.setFloat64(9, g_mouseFieldY, !0), b.setUint32(17, 0, !0), h.send(a)) | |
} | |
} | |
function sendNickName() { | |
if (null != h && h.readyState == h.OPEN && null != g_nickName) { | |
var a = new ArrayBuffer(1 + 2 * g_nickName.length), b = new DataView(a); | |
b.setUint8(0, 0); | |
for (var c = 0; c < g_nickName.length; ++c) | |
b.setUint16(1 + 2 * c, g_nickName.charCodeAt(c), !0); | |
h.send(a) | |
} | |
} | |
function sendUint8(a) { | |
if (null != h && h.readyState == h.OPEN) { | |
var b = new ArrayBuffer(1); | |
(new DataView(b)).setUint8(0, a); | |
h.send(b) | |
} | |
} | |
function drawStep() { | |
draw(); | |
win.requestAnimationFrame(drawStep) | |
} | |
function onWindowResized() { | |
winWidth = win.innerWidth; | |
winHeight = win.innerHeight; | |
g_canvasElem.width = g_canvasElem.width = winWidth; | |
g_canvasElem.height = g_canvasElem.height = winHeight; | |
draw() | |
} | |
function updateScale() { | |
if (0 != g_myParts.length) { | |
for (var a = 0, b = 0; b < g_myParts.length; b++) | |
a += g_myParts[b].size; | |
// almost always a is less than 1, except a huge monitor. | |
a = Math.pow(Math.min(64 / a, 1), .4) * Math.max(winHeight / 965, winWidth / 1920); | |
// it seems s should be between 0.9 and 1.0. | |
s = (9 * s + a) / 10; | |
} | |
} | |
function draw() { | |
var drawingStartedAt_msec = +new Date; | |
++Ba; | |
updateScale(); | |
F = +new Date; | |
if (0 < g_myParts.length) { | |
for (var b = 0, c = 0, f = 0; f < g_myParts.length; f++) | |
g_myParts[f].updatePos(), b += g_myParts[f].x / g_myParts.length, c += g_myParts[f].y / g_myParts.length; | |
g_viewPortCenterX = (g_viewPortCenterX + b) / 2; | |
g_viewPortCenterY = (g_viewPortCenterY + c) / 2 | |
} | |
va(); | |
updateMouseCoordinates(); | |
d.clearRect(0, 0, winWidth, winHeight); | |
d.fillStyle = ba ? "#111111" : "#F2FBFF"; | |
d.fillRect(0, 0, winWidth, winHeight); | |
d.save(); | |
d.strokeStyle = ba ? "#AAAAAA" : "#000000"; | |
d.globalAlpha = .2; | |
d.scale(s, s); | |
b = winWidth / s; | |
c = winHeight / s; | |
var gridSize = 50; | |
for (f = -.5 + (-g_viewPortCenterX + b / 2) % gridSize; f < b; f += gridSize) | |
d.beginPath(), d.moveTo(f, 0), d.lineTo(f, c), d.stroke(); | |
for (f = -.5 + (-g_viewPortCenterY + c / 2) % gridSize; f < c; f += gridSize) | |
d.beginPath(), d.moveTo(0, f), d.lineTo(b, f), d.stroke(); | |
d.restore(); | |
g_allItems.sort(function(a, b) { | |
return a.size == b.size ? a.id - b.id : a.size - b.size | |
}); | |
d.save(); | |
d.translate(winWidth / 2, winHeight / 2); | |
d.scale(s, s); | |
d.translate(-g_viewPortCenterX, -g_viewPortCenterY); | |
// draw some stuff | |
//d.lineWidth = 10; | |
//d.beginPath(), d.moveTo(100, 100), d.lineTo(2000, 2000), d.stroke(); | |
for (f = 0; f < E.length; f++) | |
E[f].draw(); | |
for (f = 0; f < g_allItems.length; f++) | |
g_allItems[f].draw(); | |
d.restore(); | |
g_leaderBoardCanvas && 0 != g_leaders.length && d.drawImage(g_leaderBoardCanvas, winWidth - g_leaderBoardCanvas.width - 10, 10); | |
g_maxScores = Math.max(g_maxScores, calcScoresFromCurrentSize()); | |
0 != g_maxScores && (null == O && (O = new ItemStyle(24, "#FFFFFF")), O.setValue("Score: " + ~~(g_maxScores / 100)), c = O.render(), b = c.width, d.globalAlpha = .2, d.fillStyle = "#000000", d.fillRect(10, winHeight - 10 - 24 - 10, b + 10, 34), d.globalAlpha = 1, d.drawImage(c, 15, winHeight - 10 - 24 - 5)); | |
drawSplitImageButton(); | |
drawingTime_msec = +new Date - drawingStartedAt_msec; | |
// (drawingTime_msec > 1E3 / 60) => if FPS < 60 then g_circlePointsNumberFactor -= .01 | |
// (drawingTime_msec < 1E3 / 65) => if FPS > 65 then g_circlePointsNumberFactor += .01 | |
drawingTime_msec > 1E3 / 60 ? g_circlePointsNumberFactor -= .01 : drawingTime_msec < 1E3 / 65 && (g_circlePointsNumberFactor += .01); | |
// g_circlePointsNumberFactor belongs to [0.4, 1.0] | |
.4 > g_circlePointsNumberFactor && (g_circlePointsNumberFactor = .4); | |
1 < g_circlePointsNumberFactor && (g_circlePointsNumberFactor = 1) | |
} | |
function drawSplitImageButton() { | |
if (isMobile && g_splitImageElem.width) { | |
var a = winWidth / 5; | |
d.drawImage(g_splitImageElem, 5, 5, a, a) | |
} | |
} | |
function calcScoresFromCurrentSize() { | |
for (var a = 0, b = 0; b < g_myParts.length; b++) | |
a += g_myParts[b].nSize * g_myParts[b].nSize; | |
return a | |
} | |
function predrawLeaders() { | |
if (0 != g_leaders.length) | |
if (g_areNamesUsed) { | |
g_leaderBoardCanvas = document.createElement("canvas"); | |
var a = g_leaderBoardCanvas.getContext("2d"), b = 60 + 24 * g_leaders.length, c = Math.min(200, .3 * winWidth) / 200; | |
g_leaderBoardCanvas.width = 200 * c; | |
g_leaderBoardCanvas.height = b * c; | |
a.scale(c, c); | |
a.globalAlpha = .4; | |
a.fillStyle = "#000000"; | |
a.fillRect(0, 0, 200, b); | |
a.globalAlpha = 1; | |
a.fillStyle = "#FFFFFF"; | |
c = null; | |
c = "Leaderboard"; | |
a.font = "30px Ubuntu"; | |
a.fillText(c, 100 - a.measureText(c).width / 2, 40); | |
a.font = "20px Ubuntu"; | |
for (b = 0; b < g_leaders.length; ++b) | |
c = g_leaders[b].name || "An unnamed cell", -1 != g_myParts.indexOf(g_leaders[b].id) && (c = n[0].name), g_areNamesUsed || 0 != g_myParts.length && | |
g_myParts[0].name == c || (c = "An unnamed cell"), c = b + 1 + ". " + c, a.fillText(c, 100 - a.measureText(c).width / 2, 70 + 24 * b) | |
} else | |
g_leaderBoardCanvas = null | |
} | |
function Item(itemId, itemX, itemY, itemSize, itemColor, isItemVirus, itemName) { | |
g_allItems.push(this); | |
g_allItemsIndexedByID[itemId] = this; | |
this.id = itemId; | |
this.ox = this.x = itemX; | |
this.oy = this.y = itemY; | |
this.oSize = this.size = itemSize; | |
this.color = itemColor; | |
this.isVirus = isItemVirus; | |
this.points = []; | |
this.pointsAcc = []; | |
this.createPoints(); | |
this.setName(itemName) | |
} | |
function toColorHexString(a) { | |
for (a = a.toString(16); 6 > a.length; ) | |
a = "0" + a; | |
return "#" + a | |
} | |
function ItemStyle(a, b, c, d) { | |
a && (this._size = a); | |
b && (this._color = b); | |
this._stroke = !!c; | |
d && (this._strokeColor = d) | |
} | |
if ("agar.io" != win.location.hostname && "localhost" != win.location.hostname && "10.10.2.13" != win.location.hostname) | |
win.location = "http://agar.io/"; | |
else { | |
var g_canvasElem, d, g_canvasElem, winWidth, winHeight, g_quadTree = null, h = null, g_viewPortCenterX = 0, g_viewPortCenterY = 0, g_myPartIDs = [], g_myParts = [], g_allItemsIndexedByID = {}, g_allItems = [], E = [], g_leaders = [], g_mouseX = 0, g_mouseY = 0, g_mouseFieldX = -1, g_mouseFieldY = -1, Ba = 0, F = 0, g_nickName = null, g_fieldLeft = 0, g_fieldTop = 0, g_fieldRight = 1E4, g_fieldBottom = 1E4, s = 0.4, g_region = null, sa = !0, g_areNamesUsed = true, g_notUseColor = false, g_onePartEaten = true, g_maxScores = 0, ba = false, ta = !1, isMobile = "ontouchstart" in win && /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent), g_splitImageElem = new Image; | |
g_splitImageElem.src = "img/split.png"; | |
var normalizedRegionTexts = null; | |
win.setNick = function(nickName) { | |
$jq("#adsBottom").hide(); | |
g_nickName = nickName; | |
sendNickName(); | |
$jq("#overlays").hide(); | |
g_maxScores = 0 | |
}; | |
win.setRegion = onRegionChosen; | |
win.setSkins = function(a) { | |
sa = a | |
}; | |
win.setNames = function(a) { | |
g_areNamesUsed = a | |
}; | |
win.setDarkTheme = function(a) { | |
ba = a | |
}; | |
win.setColors = function(a) { | |
g_notUseColor = a | |
}; | |
win.setShowMass = function(a) { | |
ta = a | |
}; | |
win.connect = connectTo; | |
var qa = -1, ra = -1, g_leaderBoardCanvas = null, g_circlePointsNumberFactor = 1, O = null, R = {}, Regions = "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"]; | |
Item.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: false, isVirus: false, | |
destroy: function() { | |
var a; | |
for (a = 0; a < g_allItems.length; a++) | |
if (g_allItems[a] == this) { | |
g_allItems.splice(a, 1); | |
break | |
} | |
delete g_allItemsIndexedByID[this.id]; | |
a = g_myParts.indexOf(this); | |
-1 != a && (g_onePartEaten = true, g_myParts.splice(a, 1)); | |
a = g_myPartIDs.indexOf(this.id); | |
-1 != a && g_myPartIDs.splice(a, 1); | |
this.destroyed = true; | |
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 ItemStyle(this.getNameSize(), "#FFFFFF", /*stroke*/true, "#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 * s * (this.isVirus ? Math.min(2 * g_circlePointsNumberFactor, 1) : g_circlePointsNumberFactor), | |
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 = false, k = a[e].x, p = a[e].y; | |
g_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 = true) | |
}); | |
!m && (a[e].x < g_fieldLeft || a[e].y < g_fieldTop || a[e].x > g_fieldRight || a[e].y > g_fieldBottom) && (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 < g_viewPortCenterX - winWidth / 2 / s || this.y + this.size + 40 < g_viewPortCenterY - winHeight / 2 / s || this.x - this.size - 40 > g_viewPortCenterX + winWidth / 2 / s || this.y - this.size - 40 > g_viewPortCenterY + winHeight / 2 / s ? !1 : !0 | |
},draw: function() { | |
if (this.shouldRender()) { | |
d.save(); | |
this.drawTime = F; | |
var a = this.updatePos(); | |
this.destroyed && (d.globalAlpha *= 1 - a); | |
this.movePoints(); | |
g_notUseColor ? (d.fillStyle = "#FFFFFF", d.strokeStyle = "#AAAAAA") : (d.fillStyle = this.color, d.strokeStyle = this.color); | |
d.beginPath(); | |
d.lineWidth = 10; | |
d.lineCap = "round"; | |
d.lineJoin = this.isVirus ? "mitter" : "round"; | |
a = this.getNumPoints(); | |
d.moveTo(this.points[0].x, this.points[0].y); | |
for (var b = 1; b <= a; ++b) { | |
var c = b % a; | |
d.lineTo(this.points[c].x, this.points[c].y) | |
} | |
d.closePath(); | |
a = this.name.toLowerCase(); | |
sa ? -1 != Regions.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; | |
d.stroke(); | |
d.fill(); | |
null != b && 0 < b.width && !a && (d.save(), d.clip(), d.drawImage(b, this.x - this.size, this.y - this.size, 2 * this.size, 2 * this.size), d.restore()); | |
if (g_notUseColor || 15 < this.size) | |
d.strokeStyle = "#000000", d.globalAlpha *= .1, d.stroke(); | |
d.globalAlpha = 1; | |
null != b && 0 < b.width && a && d.drawImage(b, this.x - 2 * this.size, this.y - 2 * this.size, 4 * this.size, 4 * this.size); | |
a = -1 != g_myParts.indexOf(this); | |
b = ~~this.y; | |
(g_areNamesUsed || a) && this.name && this.nameCache && (c = this.nameCache.render(), d.drawImage(c, ~~this.x - ~~(c.width / 2), b - ~~(c.height / 2)), b += c.height / 2 + 4); | |
ta && a && (null == this.sizeCache && (this.sizeCache = new ItemStyle(this.getNameSize() / 2, "#FFFFFF", /*stroke*/true, "#000000")), this.sizeCache.setSize(this.getNameSize() / 2), this.sizeCache.setValue(~~(this.size * this.size / 100)), c = this.sizeCache.render(), d.drawImage(c, ~~this.x - ~~(c.width / 2), b - ~~(c.height / 2))); | |
d.restore() | |
} | |
}}; | |
ItemStyle.prototype = {_value: "",_color: "#000000",_stroke: true,_strokeColor: "#000000",_size: 16,_canvas: null,_ctx: null,_dirty: true,setSize: function(a) { | |
this._size != a && (this._size = a, this._dirty = true) | |
},setColor: function(a) { | |
this._color != a && (this._color = a, this._dirty = true) | |
},setStroke: function(a) { | |
this._stroke != a && (this._stroke = a, this._dirty = true) | |
},setStrokeColor: function(a) { | |
this._strokeColor != a && (this._strokeColor = a, this._dirty = true) | |
},setValue: function(a) { | |
a != this._value && (this._value = a, this._dirty = true) | |
},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 | |
}}; | |
win.onload = init | |
} | |
})(window, jQuery, window, jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Свяжись со мной в скайпе ytrioq бот можно переделать и зделать так чтобы работал
Будем этим заниматься в месте.
Есть небольшие разработки которые (слабенько) работают