(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 !carad 0 .moveto 0 !cacnt (360. !cacnt .div .add .dup .dup .cos !carad .mul .exch .sin !carad .mul .lineto).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, intensity value [0..1].)
(.icolor 0 0 .moveto (.lineto).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
 newpath 4 .copy  .exch !arclhw .add .exch (addpoint).cvx arc .exch !arclhw .sub .exch (.lineto).cvx narc .drawarea)/xdef

(firstpoint) .true .def
(newpath) {(firstpoint) .true .store}.cvx .def
(addpoint) {firstpoint {.moveto (firstpoint) .false .store}.cvx {.lineto}.cvx .ifelse}.cvx .def

(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 
1.0 !apc .div (!apcl) .exch .def
.pushdc  0 !apc (!apcl .add .dup  !sat !bright .hsvcolor 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 255.0 .div .def (!bright)  1.0 .def
24 25 colorarc
(!sat) 75 255.0 .div .def
24 65 colorarc
(!sat) 120 255.0 .div .def
24 105 colorarc
(!sat) 165 255.0 .div .def
48 145 colorarc
(!sat) 210 255.0 .div .def
48 185 colorarc
(!sat) 1.0 .def
48 225 colorarc
.popdc
.pushdc
96 72 .translate 0 0 0 .icolor 
.pushdc 0 0 0 16 (0 0 27 36 .drawbox 27 0 .translate 15.999 255.0 .div .add  3 .copy .hsvcolor ).cvx .rept .pop .pop .pop 
.popdc
0 0 .setcp 0 36 .drawto 16 27 .mul 36 .drawto 16 27 .mul 0 .drawto 0 0 .drawto
 .popdc
) /xdef