Skip to content

Instantly share code, notes, and snippets.

@bmander
Created May 15, 2012 15:54
Show Gist options
  • Save bmander/2702832 to your computer and use it in GitHub Desktop.
Save bmander/2702832 to your computer and use it in GitHub Desktop.
lumpy circle
function makecircle(r){
return function(x,y){
return Math.pow(x,2) + Math.pow(y,2) < Math.pow(r,2);
}
}
function translate(tx, ty, func){
return function(x,y){
var xprime = x-tx;
var yprime = y-ty;
return func(xprime,yprime);
}
}
function rotate(theta, func){
return function(x,y){
var xprime = Math.cos(theta)*x-Math.sin(theta)*y;
var yprime = Math.sin(theta)*x+Math.cos(theta)*y;
return func(xprime,yprime);
}
}
function union(funcs){
var metaargs=arguments;
return function(x,y) {
var ret=false;
for(var i=0; i<metaargs.length;i++){
ret = ret || metaargs[i](x,y);
}
return ret;
}
}
function cut( pos, neg ){
return function(x,y){ return pos(x,y) && !neg(x,y); };
}
function nothing(){
return function(x,y){return false};
}
function scale(sx, sy, func){
return function(x,y){
return func(x/sx, y/sy);
}
}
function dist(x,y){
return Math.pow(Math.pow(x,2)+Math.pow(y,2),0.5);
}
function bulge(cx,cy,func){
return function(x,y){
var dd = (dist(x-cx,y-cy));
var tt = Math.exp(-dd*0.2)*10;
var xp = x-(tt);
var yp = y-(tt);
return func(xp,yp);
}
}
emit( translate(250,250,
scale(1.6,1.6,
bulge(29,44,
makecircle(50)
)
)
) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment