It's an entertaining exercise, especially when you watch your computer chew away for several minutes before telling you that π is probably somewhere around 3.26.
You can optimize that JS code a lot by using the unit circle, limiting yourself to the first quadrant, and using multiplication instead of Math.pow(). Then you can make it branchless using a little bitwise trickery. The result is this: https://gist.github.com/osuushi/5022143 .
OK, so I was going to just do the unit circle thing. Then I got stuck in optimization mode. God I miss performance graphics programming.