This is a port of the code from here to JavaScript. It depends on the <canvas> tag, which all modern browsers support. I wrote it originally in 2006 using a simplified approximation for performance reasons, and modified it in 2014 since web browser performance improved enough to make the unsimplified algorithm usable.