Draw circles in HTML Canvas using .arc

Share this video with your friends

Send Tweet

Circles are one of the most difficult and prestigious shapes to achieve in Canvas. No circle method is provided, instead, we must utilize the .arc method to achieve circle happiness.

The .arc method however is a bit funny, it doesn’t use degrees like we’re used to, instead it uses radians. So in this lesson we’ll also learn how we can use some maths to be able to enter the familiar degrees.

Maria
Maria
~ 7 years ago

Shouldn't it be:

ctx.arc(50, 50, 20, 0, Math.PI * 2);

and not

ctx.arc(50, 50, 20, 0, Math.PI/0.5); ?

Because 360/180 = 2. Don't understand how you came up with 0.5.

~ 5 years ago

dividing by 0.5 is the same as multiplying by 2 however, you are right, in mathematics, 360 degrees is universally known as 2 pi radians.