%!
/xdef {exch def} bind def
/MyShape {
10 dict begin
/fflag xdef %put on local variable
/sides xdef
fflag % if shape is filled
{
aload pop % flat out array
newpath
moveto %first point is initial position
1 1 sides
{
pop %discard the for-loop item variable
lineto
} for
closepath fill
}
%not filled
{
aload pop
% draw the sides
newpath
2 setlinewidth
moveto
1 1 sides {
2 mod 0 ne
{moveto} % even sides, no draw
{lineto currentpoint stroke moveto} % odd sides
ifelse
} for
}
ifelse
end
} bind def
[100 100 150 100 150 50 100 50 100 100] 4 true MyShape
0 80 translate
[100 100 150 100 150 50 100 50 100 100] 4 false MyShape
showpage