Am trying to draw a star using canvas, but the code is not running. I want to understand: what are the steps to measure the Y and X coordinate? How to find them? to draw any
//function to draw star with N spikes
//centered on a circle of radius R, centered on (cX,cY)
function star(R, cX, cY, N) {
//star draw
ctx.beginPath();
ctx.moveTo(cX + R,cY);
for(var i = 1; i <= N * 2; i++)
{
if(i % 2 == 0){
var theta = i * (Math.PI * 2) / (N * 2);
var x = cX + (R * Math.cos(theta));
var y = cY + (R * Math.sin(theta));
} else {
var theta = i * (Math.PI * 2) / (N * 2);
var x = cX + ((R/2) * Math.cos(theta));
var y = cY + ((R/2) * Math.sin(theta));
}
ctx.lineTo(x ,y);
}
ctx.closePath();
ctx.stroke();
}