Created
April 12, 2012 19:47
-
-
Save bmander/2370519 to your computer and use it in GitHub Desktop.
bulge spiral
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 translate(tx, ty, func){ | |
return function(x,y){ | |
var xprime = x-tx; | |
var yprime = y-ty; | |
return func(xprime,yprime); | |
} | |
} | |
function dist(x,y){ | |
return Math.pow(Math.pow(x,2)+Math.pow(y,2),0.5); | |
} | |
function spiral(a, func){ | |
return function(x,y){ | |
var tt = dist(x,y)*a; | |
var xprime = Math.cos(tt)*x-Math.sin(tt)*y; | |
var yprime = Math.sin(tt)*x+Math.cos(tt)*y; | |
return func(xprime,yprime); | |
} | |
} | |
function bulge(a,func){ | |
return function(x,y){ | |
var tt = dist(x,y)*a; | |
var xp = tt*x; | |
var yp = tt*y; | |
return func(xp,yp); | |
} | |
} | |
function makeline(width){ | |
return function(x,y){ | |
return y<width/2 && y > -width/2; | |
} | |
} | |
function foobar(x,y){ | |
return translate(150,150, | |
scale(3,3, | |
bulge(0.001, | |
spiral(0.03, | |
makeline(40) | |
)) | |
) | |
); | |
} | |
function scale(sx, sy, func){ | |
return function(x,y){ return func(x*sx,y*sy);} | |
} | |
emit( foobar() ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you should use http://bl.ocks.org to render these