It's basically the same, just change SHP_POINT to SHP_POLYGON (in 2 places) and add cycle for points of polygon. Here is sample which generates polygon shapefile with random circles. I guess you'll be able to write what you need looking at both samples.
Hope it helps,
Sergei
Hope it helps,
Sergei