If I'm given a number of vertices/edges, how can I dynamically draw a polygon?

Code:
function drawPolygon($edges) {
    imagepolygon(/* ... */);
}