Skip to content

Instantly share code, notes, and snippets.

@alanedwardes
Created December 24, 2011 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanedwardes/1518434 to your computer and use it in GitHub Desktop.
Save alanedwardes/1518434 to your computer and use it in GitHub Desktop.
length = Math.max(canvas.width, canvas.height);
// Make sure the rays are bigger than the canvas
midx = canvas.width / 2, midy = canvas.height / 2;
// Get the mid point of our canvas
var d = 12;
// how many rays (or divisions)
for(i = 0;i < d;i++){
angle = (Math.PI * 2 / d) * i;
// 360 degrees is Math.PI * 2:
// we're getting that divided by
// divisions times loop interations
context.moveTo(midx, midy);
// Move to the middle of the canvas
c1 = getXY(midx, midy, length, angle + d / 100);
// Calculate the first co-ordinates
context.lineTo(c1.x, c1.y);
// Line from the middle to the first co-ordinates
c2 = getXY(midx, midy, length, angle - d / 100);
// Calculate the second co-ordinates
context.lineTo(c2.x, c2.y);
// Line to the second co-ordinates
context.lineTo(midx, midy);
// Line back to the middle
context.fill();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment