Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tutorial for HTML canvas's arc function [closed]

I can not figure out what all the parameters to the arc() function are (by experimentation) and I have not found any tutorial that seems to explain them. Where would a good explanation of the arc() function be?

like image 285
Alexander Bird Avatar asked Nov 25 '08 23:11

Alexander Bird


People also ask

What is CTX arc?

ctx.arc(x, y, radius, startAngle, endAngle [, antiClockwise]) The arc() method draws a circular arc centered at (x,y) with the radius of radius . The arc will start at startAngle and end at endAngle . Both startAngle and endAngle are in radians. Since π radians = 180 degrees , 1 radian is about π/ 180 degrees.

How do you create an arc in HTML CSS?

CSS Shapes It's possible to draw circles and arcs in CSS by simply creating a square <div> and setting border-radius to 50%. Each side of the border can take a different color or can be set to transparent . The background-color property sets the shape's fill, if any.

Which of the following HTML canvas methods adds an arc to the current subpath?

arc() method of the Canvas 2D API adds a circular arc to the current sub-path.


2 Answers

arc(x, y, radius, startAngle, endAngle, anticlockwise)

The first three parameters, x and y and radius, describe a circle, the arc drawn will be part of that circle. startAngle and endAngle are where along the circle to start and stop drawing. 0 is east, Math.PI/2 is south, Math.PI is west, and Math.PI*3/2 is north. If anticlockwise is 1 then the direction of the arc is reversed.

https://developer.mozilla.org/En/Canvas_tutorial/Drawing_shapes#Arcs

Clockwise

AntiClockwise

In the attached diagrams, the only difference is the anticlockwise param. Math.PI/2 always ends south when clockwise or anticlockwise

like image 174
Sparr Avatar answered Oct 16 '22 23:10

Sparr


I was having the same problem and made a little interactive page to help make sense of it:

http://www.scienceprimer.com/drawing-circles-javascript-html5-canvas-element

All of the parameters can be adjusted and the resulting arc is rendered in real time. The page also demonstrates how the fill(), stroke() and closePath() methods interact with the arc() method.

like image 21
Andrew Staroscik Avatar answered Oct 17 '22 01:10

Andrew Staroscik