Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to draw a half circle with arc on html5 canvas using the mouse. I got the start point from the mouse coordinates. I want to be able to draw the half circle as im moving the mouse and cant figure out how to do it.
Posted
Comments
Maciej Los 12-Aug-13 7:52am    
Have you seen this: HTML5 Quick Start Web Application[^]?

1 solution

Have a look here: The Developer’s Guide to HTML5 Canvas[^].

[EDIT]
arc method[^]

C#
//ctx is a canvas context
ctx.beginPath();
var x = 50;               // The x-coordinate.
var y = 50;               // The y-coordinate.
var radius = 20;          // The arc radius; you need to calculate it, if you want to set it using mouse
var startAngle = 0;                     // The starting point on the circle.
//endAngle in radius = angle * (Math.PI / 180)
var endAngle = 180 * (Math.PI / 180); // The end point on the circle, half a circle = 180 degrees
var clockwise =  false // The direction of drawing = clock wise
ctx.arc(x, y, radius, startAngle, endAngle, clockwise); // Create the arc path.
ctx.stroke();



[/EDIT]
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 12-Aug-13 17:27pm    
My 5 (hope it works :-)
—SA
Maciej Los 12-Aug-13 17:31pm    
I'm not sure, but i spend about 10-15 minutes reading documentation...
Half of circle should be drawed from right to bottom and to the left. It should looks like a smile ;)
Sergey Alexandrovich Kryukov 12-Aug-13 17:44pm    
I would spend an extra minute to test it, but you would take a chance to do it if OP complains...
—SA
Maciej Los 12-Aug-13 17:49pm    
;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900