Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Partially deobfuscated hexasphere.js april fools day joke - http://pub.ist.ac.at/~edels/hexasphere/
function canvasApp() {
if (!canvasSupport()) {
return;
}
var canvas = document.getElementById('canvasOne');
var ctx = canvas.getContext('2d');
setup();
var _0xa67bx4;
var _0xa67bx5;
var _0xa67bx6;
var pointScalingFactor;
var pointA; // ?
var pointB; // ?
var lineScalingFactor;
var _0xa67bxb;
var _0xa67bxc;
var _0xa67bxd;
var _0xa67bxe;
var _0xa67bxf;
var mouseIsDown;
var _0xa67bx11;
var _0xa67bx12;
var _0xa67bx13;
var _0xa67bx14;
var animationInterval;
function setup() {
_0xa67bx4 = [0, 0];
_0xa67bx5 = [0, 0];
_0xa67bx6 = 0;
lineScalingFactor = 150;
pointScalingFactor = 0.1;
pointA = [pointScalingFactor, 0];
pointB = [pointScalingFactor * 0.5, pointScalingFactor * 0.5 * Math.sqrt(3)];
_0xa67bxb = [0, 0];
_0xa67bxc = [];
_0xa67bxd = [];
buildStartingPoints();
_0xa67bxe = [0.0, 0.0];
_0xa67bxf = 0.0;
draw();
canvas.addEventListener('mousedown', onMouseDown, false);
}
function distance(pointA, pointB) {
var _0xa67bx1d = pointA[0] - pointB[0];
var _0xa67bx1e = pointA[1] - pointB[1];
return Math.sqrt(_0xa67bx1d * _0xa67bx1d + _0xa67bx1e * _0xa67bx1e);
}
function buildStartingPoints() {
var x,y;
for (x = -30; x < 30; ++x) {
for (y = -30; y < 30; ++y) {
var point = [pointA[0] * x + pointB[0] * y, pointA[1] * x + pointB[1] * y];
if ((x - y) % 3 !== 0) {
_0xa67bxc.push(point);
}
}
}
for (x = 0; x < _0xa67bxc[length]; ++x) {
for (y = x + 1; y < _0xa67bxc[length]; ++y) {
if (distance(_0xa67bxc[x], _0xa67bxc[y]) < pointScalingFactor * 1.01) {
_0xa67bxd.push([idx, innerIdx]);
}
}
}
}
function onMouseDown(event) {
var rect = canvas.getBoundingClientRect();
_0xa67bx11 = 2 * (event.clientX - rect.left) / rect.width - 1;
_0xa67bx12 = 2 * (event.clientY - rect.top) / rect.height - 1;
_0xa67bx13 = _0xa67bx11;
_0xa67bx14 = _0xa67bx12;
mouseIsDown = true;
_0xa67bx4 = [_0xa67bx11, _0xa67bx12];
if (mouseIsDown) {
window.addEventListener('mousemove', onMouseMove, false);
animationInterval = setInterval(drawLoop, 1000 / 60);
}
canvasremoveEventListener('mousedown', onMouseDown, false);
window.addEventListener('mouseup', onMouseUp, false);
if (event.preventDefault) {
event.preventDefault();
} else {
if (event.returnValue) {
event.returnValue = false;
}
}
return false;
}
function drawLoop() {
if (!mouseIsDown) {
clearInterval(animationInterval);
}
draw();
}
function onMouseUp(event) {
canvas.addEventListener('mousedown', onMouseDown, false);
window.removeEventListener('mouseup', onMouseUp, false);
if (mouseIsDown) {
mouseIsDown = false;
window.removeEventListener('mousemove', onMouseMove, false);
}
}
function vecLength(pointA) {
return Math.sqrt(pointA[0] * pointA[0] + pointA[1] * pointA[1]);
}
function canvas9(pointA, pointB) {
var canvasa = Math.asin((pointA[0] * pointB[1] - pointA[1] * pointB[0]) / vecLength(pointA) / vecLength(pointB));
if (pointA[0] * pointB[0] + pointA[1] * pointB[1] < 0) {
if (canvasa > 0) {
canvasa = Math.PI - canvasa;
} else {
canvasa = -Math.PI - canvasa;
}
}
return canvasa;
}
function onMouseMove(event) {
var idx = 0;
var rect = canvas.getBoundingClientRect();
_0xa67bx11 = 2 * (event.clientX - rect.left) / rect.width - 1;
_0xa67bx12 = 2 * (event.clientY - rect.top) / rect.height - 1;
_0xa67bx4 = [_0xa67bx13, _0xa67bx14];
_0xa67bx5 = [_0xa67bx11, _0xa67bx12];
_0xa67bxb[0] = _0xa67bx5[0] - _0xa67bx4[0];
_0xa67bxb[1] = _0xa67bx5[1] - _0xa67bx4[1];
var canvasc;
if (vecLength(_0xa67bxb) < 1e-6) {
canvasc = vecLength(_0xa67bx4);
} else {
canvasc = vecLength(_0xa67bx4) - Math.abs(_0xa67bxb[0] * _0xa67bx4[0] + _0xa67bxb[1] * _0xa67bx4[1]) / vecLength(_0xa67bxb);
}
if (canvasc < 0.0) {
canvasc = 0.0;
}
if (canvasc > 1.0) {
canvasc = 1.0;
}
_0xa67bx6 = canvas9(_0xa67bx5, _0xa67bx4) * canvasc;
_0xa67bxb[0] *= (1.0 - canvasc);
_0xa67bxb[1] *= (1.0 - canvasc);
for (idx = 0; idx < _0xa67bxc[length]; ++idx) {
_0xa67bxc[idx] = ctx0(_0xa67bxc[idx], -_0xa67bx6, _0xa67bxb);
}
_0xa67bxe = ctx0(_0xa67bxe, -_0xa67bx6, _0xa67bxb);
_0xa67bxf -= _0xa67bx6;
while (vecLength(_0xa67bxe) > 3.0 * pointScalingFactor) {
var canvasd = 2e19;
var canvase = -1;
for (idx = 0; idx < 6; ++idx) {
var canvasf = _0xa67bxe[0] * Math.cos(_0xa67bxf + Math.PI / 3.0 * idx) + _0xa67bxe[1] * Math.sin(_0xa67bxf + Math.PI / 3.0 * idx);
if (canvasf < canvasd) {
canvasd = canvasf;
canvase = idx;
}
}
corr = [3.0 * pointScalingFactor * Math[cos](_0xa67bxf + Math[PI] / 3.0 * canvase), 3.0 * pointScalingFactor * Math[sin](_0xa67bxf + Math[PI] / 3.0 * canvase)];
_0xa67bxe = ctx0(_0xa67bxe, 0.0, corr);
for (idx = 0; idx < _0xa67bxc[length]; ++idx) {
_0xa67bxc[idx] = ctx0(_0xa67bxc[idx], 0.0, corr);
}
}
_0xa67bx13 = _0xa67bx11;
_0xa67bx14 = _0xa67bx12;
}
function ctx0(point, pointA, ctx1) {
var ctx2 = [
Math.cos(pointA) * point[0] - Math.sin(pointA) * point[1],
Math.sin(pointA) * point[0] + Math.cos(pointA) * point[1]
];
var ctx3 = [ctx2[0] + ctx1[0], ctx2[1] + ctx1[1]];
return ctx3;
}
function drawHexHull() {
var hullScan = new ConvexHullGrahamScan();
var ctx6 = [];
var ptsLenGreaterThanHalfPiArr = [];
var idx = 0;
for (idx = 0; idx < _0xa67bxc.length; ++idx) {
var point = _0xa67bxc[idx].slice();
var len = vecLength(point);
ptsLenGreaterThanHalfPiArr.push(len > Math.PI * 0.5);
if (len !== 0) {
point[0] *= Math.sin(len) / len;
point[1] *= Math.sin(len) / len;
}
ctx6.push(point);
if (!ptsLenGreaterThanHalfPiArr[idx]) {
hullScan.addPoint(point[0], point[1]);
}
}
ctx.beginPath();
for (idx = 0; idx < _0xa67bxd.length; ++idx) {
if (ptsLenGreaterThanHalfPiArr[_0xa67bxd[idx][0]] || ptsLenGreaterThanHalfPiArr[_0xa67bxd[idx][1]]) {
continue;
}
var ctx9 = ctx6[_0xa67bxd[idx][0]];
var ctxa = ctx6[_0xa67bxd[idx][1]];
ctx.moveTo(ctx9[0] * lineScalingFactor + lineScalingFactor, ctx9[1] * lineScalingFactor + lineScalingFactor);
ctx.lineTo(ctxa[0] * lineScalingFactor + lineScalingFactor, ctxa[1] * lineScalingFactor + lineScalingFactor);
}
var hull = hullScan.getHull();
var lastHullPoint = hull[hull.length - 1];
ctx.moveTo(lastHullPoint.x * lineScalingFactor + lineScalingFactor, lastHullPoint.y * lineScalingFactor + lineScalingFactor);
for (idx = 0; idx < hull.length; ++idx) {
ctx.lineTo(hull[idx].x * lineScalingFactor + lineScalingFactor, hull[idx].y * lineScalingFactor + lineScalingFactor);
ctx.moveTo(hull[idx].x * lineScalingFactor + lineScalingFactor, hull[idx].y * lineScalingFactor + lineScalingFactor);
}
ctx.strokeStyle = '#000066';
ctx.stroke();
}
function draw() {
ctx.fillStyle = 'white';
ctx.fillRect(0, 0, canvas.width, canvas.height);
drawHexHull();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.