Skip to content

Instantly share code, notes, and snippets.

@karlin
Created December 18, 2012 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karlin/4332210 to your computer and use it in GitHub Desktop.
Save karlin/4332210 to your computer and use it in GitHub Desktop.
Another Inlet
{"description":"Another Inlet","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"tab":"edit","display_percent":0.35552325581395344,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"hidepanel":false}
var w = 300,
h = 406,
p = [10, 20, 30, 30],
x = d3.scale.linear().domain([0, 2.112]).range([0, w]),
y = d3.scale.linear().domain([0, 6]).range([h, 0]);
var svg = d3.select("svg")
.attr("width", w + p[1] + p[3])
.attr("height", h + p[0] + p[2])
.append("g")
.attr("transform", "translate(" + p[3] + "," + p[0] + ")");
svg.append("g")
.attr("transform", "translate(0," + y(0) + ")")
.call(d3.svg.axis().scale(x));
svg.append("g")
.attr("transform", "translate(" + x(0) + ")")
.call(d3.svg.axis().scale(y).orient("left"));
svg.append("path")
.data([d3.range(0, 1.40575, 0.00851).map(f)])
.attr("fill", "none")
.attr("stroke", "#FF4455")
.attr("d", d3.svg.line()
.interpolate("basis")
.x(function(d, i) { return x(i * .01); })
.y(y));
function f(n) { return Math.pow(4, n * n) - factorial(Math.pow(n, 4)); }
// From: http://stackoverflow.com/a/3959372/64009
function factorial(op) {
// Lanczos Approximation of the Gamma Function
// As described in Numerical Recipes in C (2nd ed. Cambridge University Press, 1992)
var z = op + 1;
var p = [1.000000000190015, 76.18009172947146, -86.50532032941677, 24.01409824083091, -1.231739572450155, 1.208650973866179E-3, -5.395239384953E-6];
var d1 = Math.sqrt(2 * Math.PI) / z;
var d2 = p[0];
for (var i = 1; i <= 6; ++i)
d2 += p[i] / (z + i);
var d3 = Math.pow((z + 5.5), (z + 0.5));
var d4 = Math.exp(-(z + 5.5));
d = d1 * d2 * d3 * d4;
return d;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment