Skip to content

Instantly share code, notes, and snippets.

@chrillo
Created November 23, 2011 14:07
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrillo/1388743 to your computer and use it in GitHub Desktop.
Save chrillo/1388743 to your computer and use it in GitHub Desktop.
Draw a star in html canvas
/*
takes the x,y coordinates, the number of spikes, the inner and the outer radius of the spikes
*/
function drawStar(ctx,cx,cy,spikes,r0,r1){
var rot=Math.PI/2*3,x=cx,y=cy,step=Math.PI/spikes
ctx.strokeSyle="#000";
ctx.beginPath();
ctx.moveTo(cx,cy-r0)
for(i=0;i<spikes;i++){
x=cx+Math.cos(rot)*r0;
y=cy+Math.sin(rot)*r0;
ctx.lineTo(x,y)
rot+=step
x=cx+Math.cos(rot)*r1;
y=cy+Math.sin(rot)*r1;
ctx.lineTo(x,y)
rot+=step
}
ctx.lineTo(cx,cy-r0)
ctx.stroke();
ctx.closePath();
}
@zevarito
Copy link

Satan style was on purpose?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment