I'm trying to create a "starburst" effect using a canvas, but the lines of the segments seem incredibly uneven. Am I doing something wrong?
var rays = 40; var canvas = $("header canvas")[0]; var ctx = canvas.getContext("2d"); var centre = [canvas.width*0.2,canvas.height*0.90]; var radius = Math.sqrt(Math.pow(canvas.width,2)+Math.pow(canvas.height,2)); var colours = ["red","white"]; var segment = 2*Math.PI/rays; for(var i=0;i<rays;i++){ ctx.beginPath(); ctx.moveTo(centre[0], centre[1]); ctx.arc( centre[0], centre[1], radius, segment * i, segment * (i+1), false ); ctx.lineTo(centre[0], centre[1]); ctx.closePath(); ctx.fillStyle = colours[i % colours.length]; ctx.fill(); }
source share