Created
November 23, 2011 14:07
-
-
Save chrillo/1388743 to your computer and use it in GitHub Desktop.
Draw a star in html canvas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Satan style was on purpose?