(pi) 3.1415927 .def

(circlearea) 
(circlearea takes a radius and segment count on the operand stack and draws a circular area with those parameters)
((!cacnt) .exch .def (!carad) .exch .def .startpath 0 !cacnt (360. !cacnt .div .add .dup .dup .cos !carad .mul .exch .sin !carad .mul .enterpoint).cvx .rept .pop .drawarea) /xdef

(arc)
(arc takes a beginning angle, ending angle, radius, number of steps, and procedure on the operand stack. For each point in the arc (proceeding in a counterclockwise direction) the procedure is executed.)
((!arx) .exch .def
 (!arcnt) .exch .def
 (!arr).exch .def
 (!areag) .exch .dup 0 .lt (360 .add) .cvx .if .def
 (!arbag) .exch .dup 0 .lt (360 .add) .cvx .if .def
 !areag !arbag 2 .copy .lt (.exch .sub  360 .exch .sub)(.sub)/ifelse  !arcnt 1. .sub .div (!ardel) .exch .def 
!arbag !ardel .sub !arcnt ( !ardel .add .dup .dup .cos !arr .mul .exch .sin 
!arr .mul !arx).cvx .rept .pop)/xdef

(narc)
(narc takes a beginning angle, ending angle, radius, number of steps, and procedure on the operand stack. For each point in the arc (proceeding in a clockwise direction) the procedure is executed.)
((!arx) .exch .def
 (!arcnt) .exch .def
 (!arr).exch .def
 (!areag) .exch .dup 0 .lt (360 .add) .cvx .if .def
 (!arbag) .exch .dup 0 .lt (360 .add) .cvx .if .def
 !areag !arbag 2 .copy .lt (.exch .sub  360 .exch .sub)(.sub)/ifelse  !arcnt 1. .sub .div .neg  (!ardel) .exch .def 
!areag !ardel .sub !arcnt ( !ardel .add .dup .dup .cos !arr .mul .exch .sin 
!arr .mul !arx).cvx .rept .pop)/xdef

(pieseg)
(pieseg draws a pie shaped segment given the following parameters:
Beginning angle, ending angle, radius, number of steps, greyvalue.)
(.setgrey .startpath 0 0 .enterpoint (.enterpoint).cvx arc .drawarea)/xdef

(arcline)
(arcline draws an counterclockwise arched line segment given the following parameters:
Beginning angle, ending angle, radius, number of steps, hlfwidth)
((!arclhw) .exch .def
 .startpath 4 .copy  .exch !arclhw .add .exch (.enterpoint).cvx arc .exch !arclhw .sub .exch (.enterpoint).cvx narc .drawarea)/xdef

(narcline)
(sarcline draws an clockwise arched line segment given the following parameters:
Beginning angle, ending angle, radius, number of steps, hlfwidth)
(5 -2 .roll .exch 5 2 .roll arcline)/xdef


(.abs)(.dup 0 .lt (.neg) .cvx .if) .cvx .def

(colorarc)
(colorarc draws a circle of color patches with n steps of radius r along the hue axis(takes n and r))
((!apr) .exch .def
 (!apc) .exch .def 
360. !apc .div .dup (!apd) .exch .def .85 .mul (!apt).exch .def 
240 !apc .div .cvi (!apcl) .exch .def
.pushdc  0 !apc (!apcl .add .dup  !sat !bright .color 0 !apt !apr 5 17.5 arcline !apd .rotate) .cvx .rept .pop  .popdc) /xdef

(colorchart)
(colorchart builds a circular color chart)
(.pushdc
8.5 36 .mul 11 36 .mul .translate 
(!sat) 30 .def (!bright)  255 .def
24 25 colorarc
(!sat) 75 .def
24 65 colorarc
(!sat) 120 .def
24 105 colorarc
(!sat) 165 .def
48 145 colorarc
(!sat) 210 .def
48 185 colorarc
(!sat) 255 .def
48 225 colorarc
.popdc
.pushdc
96 72 .translate 0 0 0 .color 
.pushdc 0 0 0 16 (0 0 27 36 .drawboxarea 27 0 .translate 15.999 .add  3 .copy  .cvi .color ).cvx .rept .pop .pop .pop 
.popdc
0 0 .moveto 0 36 .drawto 16 27 .mul 36 .drawto 16 27 .mul 0 .drawto 0 0 .drawto
 .popdc
) /xdef