Created
May 15, 2012 15:54
-
-
Save bmander/2702832 to your computer and use it in GitHub Desktop.
lumpy circle
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 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