Skip to content
Advertisement

Get coordinates of the points in an ellipse in HTML5 Canvas

In HTML5 Canvas, I know I can draw an ellipse with CanvasRenderingContext2D.ellipse(), but how can I draw some points on the ellipse path?

I can draw points on a circular path using the following codes:

JavaScript

Screenshot

p.s. ignore the colors and the dot at the center.

But how to do this with an ellipse? I don’t want to use ctx.scale() to distort the whole image.

Advertisement

Answer

At the moment your little rectangles are drawn along a perfect circle because the distance from the center is always the same. If you want to draw an oval, you have to vary the distance horizontally and vertically.

For example:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement