How to draw an arbitrary irregular polygon with n sides?
I am trying to find an algorithm of how to draw a simple (no lines are allowed to intersect), irregular polygon. The number of sides should be defined by the user, n>3 . Here is an intial code which only draws a complex polygon (lines intersect): var ctx = document.getElementById('drawpolygon').getContext('2d'); var sides = 10; ctx.fillStyle = '#f00'; ctx.beginPath(); ctx.moveTo(0, 0); for(var i=0;i<sides;i++) { var x = getRandomInt(0, 100); var y = getRandomInt(0, 100); ctx.lineTo(x, y); } ctx.closePath(); ctx.fill(); // https://stackoverflow.com/a/1527820/1066234 function getRandomInt(min,