Created
July 20, 2012 13:47
-
-
Save jbt/3150819 to your computer and use it in GitHub Desktop.
If you can tell me what these two functions are for, you win a prize
This file contains hidden or 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
t.prototype.REDACTED = function(a, b, j, c, g) { | |
for(var r = this.REDACTED2(0), t = Math.tan(r), C = g % 86400 / 86400 * Math.PI * 2, g = [], n = 0;n <= c + 1;n = n + 1) { | |
g[n] = Math.atan(Math.cos(2 * Math.PI * (j + n / c) / a + C) / t) / Math.PI * c * a / 2 - (b - a / 4) * c; | |
} | |
b = Math.max.apply(Math, g); | |
j = Math.min.apply(Math, g); | |
a = ""; | |
if(g[0] > 0 && g[0] < c) { | |
a = "M0," + g[0]; | |
if(b >= c) { | |
for(b = 0;b < g.length - 1;b = b + 1) { | |
if(g[b] > c) { | |
g[b - 1] > c && g[b + 1] > c || (a = a + ("L" + b + "," + c)); | |
}else { | |
if(g[b] < 0) { | |
a = a + ("L" + b + ",0"); | |
break; | |
} | |
a = a + ("L" + b + "," + g[b].toFixed(1)); | |
} | |
} | |
if(r >= 0) { | |
if(b == g.length) { | |
a = a + ("L" + c + "," + g[c].toFixed(1)); | |
a = a + ("L" + c + "," + c); | |
} | |
a = a + ("L0," + c); | |
}else { | |
b == g.length && (a = a + ("L" + c + "," + g[c].toFixed(1))); | |
a = a + ("L" + c + "," + c) + ("L" + c + ",0") + "L0,0"; | |
} | |
}else { | |
if(j <= 0) { | |
for(b = 0;b < g.length - 1;b = b + 1) { | |
g[b] < 0 ? g[b - 1] < 0 && g[b + 1] < 0 || (a = a + ("L" + b + ",0")) : a = a + ("L" + b + "," + g[b].toFixed(1)); | |
} | |
if(r >= 0) { | |
b == g.length && (a = a + ("L" + c + "," + g[c].toFixed(1))); | |
a = a + ("L" + c + ",0") + ("L" + c + "," + c) + ("L0," + c); | |
}else { | |
if(b == g.length) { | |
a = a + ("L" + c + "," + g[c].toFixed(1)); | |
a = a + ("L" + c + ",0"); | |
} | |
a = a + "L0,0"; | |
} | |
}else { | |
for(b = 0;b < g.length - 1;b = b + 1) { | |
a = a + ("L" + b + "," + g[b].toFixed(1)); | |
} | |
a = a + ("L" + c + "," + g[c].toFixed(1)); | |
a = r >= 0 ? a + ("L" + c + "," + c) + ("L0," + c) : a + ("L" + c + ",0") + "L0,0"; | |
} | |
} | |
}else { | |
if(g[c] > 0 && g[c] < c) { | |
b = 0; | |
if(g[0] <= 0) { | |
for(;g[++b] <= 0;) { | |
} | |
for(a = "M" + b + ",0";b < g.length - 1;b = b + 1) { | |
a = a + ("L" + b + "," + g[b].toFixed(1)); | |
} | |
a = r >= 0 ? a + ("L" + c + "," + c) + ("L0," + c) + "L0,0" : a + ("L" + c + ",0"); | |
}else { | |
if(g[0] >= c) { | |
for(;g[++b] >= c;) { | |
} | |
for(a = "M" + b + "," + c;b < g.length - 1;b = b + 1) { | |
a = a + ("L" + b + "," + g[b].toFixed(1)); | |
} | |
a = r >= 0 ? a + ("L" + c + "," + c) : a + ("L" + c + ",0") + "L0,0" + ("L0," + c); | |
} | |
} | |
}else { | |
if(g[0] <= 0 && g[c] <= 0) { | |
if(b < 0) { | |
a = r >= 0 ? "M0,0" + ("L" + c + ",0") + ("L" + c + "," + c) + ("L0," + c) : "M0,0"; | |
}else { | |
for(b = 0;g[++b] <= 0;) { | |
} | |
for(a = "M" + b + ",0";b < g.length;b = b + 1) { | |
if(g[b] <= 0) { | |
break; | |
} | |
a = a + ("L" + b + "," + g[b].toFixed(1)); | |
} | |
r >= 0 && (a = a + ("L" + c + ",0") + ("L" + c + "," + c) + ("L0," + c) + "L0,0"); | |
} | |
}else { | |
if(g[0] >= c && g[c] >= c) { | |
if(j > c) { | |
a = r < 0 ? "M0,0" + ("L" + c + ",0") + ("L" + c + "," + c) + ("L0," + c) : "M0,0"; | |
}else { | |
for(b = 0;g[++b] >= c;) { | |
} | |
for(a = "M" + b + "," + c;b < g.length;b = b + 1) { | |
if(g[b] >= c) { | |
break; | |
} | |
a = a + ("L" + b + "," + g[b].toFixed(1)); | |
} | |
r < 0 && (a = a + ("L" + c + ",0") + ("L" + c + "," + c) + ("L0," + c) + "L0,0"); | |
} | |
}else { | |
if(g[0] <= 0) { | |
for(b = 0;g[++b] <= 0;) { | |
} | |
for(a = "M" + b + ",0";b < g.length;b = b + 1) { | |
if(g[b] >= c) { | |
break; | |
} | |
a = a + ("L" + b + "," + g[b].toFixed(1)); | |
} | |
a = a + ("L" + b + "," + c); | |
a = r >= 0 ? a + ("L0," + c) + "L0,0" : a + ("L" + c + "," + c) + ("L" + c + ",0"); | |
}else { | |
for(b = 0;g[++b] >= c;) { | |
} | |
for(a = "M" + b + "," + c;b < g.length;b = b + 1) { | |
if(g[b] <= 0) { | |
break; | |
} | |
a = a + ("L" + b + "," + g[b].toFixed(1)); | |
} | |
a = a + ("L" + b + ",0"); | |
a = r < 0 ? a + "L0,0" + ("L0," + c) : a + ("L" + c + ",0") + ("L" + c + "," + c); | |
} | |
} | |
} | |
} | |
} | |
return a; | |
}; | |
t.prototype.REDACTED2 = function(a) { | |
a || (a = 0); | |
var b = new Date, j = b.getUTCFullYear(), c = b.getUTCMonth() + 1, g = b.getUTCDate(); | |
if(c <= 2) { | |
j = j - 1; | |
c = c + 12; | |
} | |
var r = Math.PI / 180, a = (Math.floor(365.25 * (j + 4716)) + Math.floor(30.6001 * (c + 1)) + g - Math.floor(j / 100) + Math.floor(Math.floor(j / 100) / 4) + b.getTime() % 864E5 / 864E5 + a * 1E3 - 2453068) / 36525, b = (357.52911 + a * (35999.05029 - 1.537E-4 * a)) / r; | |
return Math.asin(Math.sin((23 + 13 / 30 + (21.448 - a * 46.815 + a * a * 5.9E-4 - a * a * a * 0.001813) / 3600 + 0.00256 * Math.cos(r * (125.04 - 1934.136 * a))) * r) * Math.sin(((280.46646 + a * 36000.76983 + a * a * 3.032E-4) % 360 + Math.sin(b) * (1.914602 - a * 0.004817 + a * a * 1.4E-5) + Math.sin(b + b) * (0.019993 - a * 1.01E-4) + Math.sin(b + b + b) * 2.89E-4 - 0.00569 - 0.00478 * Math.sin((125.04 - 1934.136 * a) * r)) * r)); | |
}; |
The two functions in conjunction are probably used to project an overlay of the day / night over a map
REDACTED2: Deals with sun angle calculation
REDACTED: Creates the PATH data (SVG)
Source: http://www.edesign.nl/2009/05/14/math-behind-a-world-sunlight-map/ and here: http://en.wikipedia.org/wiki/Position_of_the_Sun
Honestly I count not really trim the values to make it work 100%, but sure enough I could make it draw something: http://jsbin.com/hinor/1/edit
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Completely unhelpful hint:
(8, 3, 4, 256, new Date / 1000)
is an example of a set of arguments that does some interesting stuff ;)