Skip to content

Instantly share code, notes, and snippets.

@bmander
Created April 12, 2012 19:47
Show Gist options
  • Save bmander/2370519 to your computer and use it in GitHub Desktop.
Save bmander/2370519 to your computer and use it in GitHub Desktop.
bulge spiral
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() );
@max-mapper
Copy link

you should use http://bl.ocks.org to render these

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment