% ps library to draw various shapes with lines eg. grids, lattice, box, etc. % % To draw a grid % x1 y1 x2 y2 sep grid % % To draw a line % x1 y1 x2 y2 line % % To draw a path connected with points % x1 y1 x2 y2 x3 y3 ... x_n y_n path stroke % % To draw a polygon from points % x1 y1 x2 y2 x3 y3 ... x_n y_n path closepath stroke % % To draw a filled polygon from points % x1 y1 x2 y2 x3 y3 ... x_n y_n path closepath fill % % To draw a box % x1 y1 x2 y2 box fill/stroke % x1 y1 x2 y2 rect fill/stroke % 'rect' is a synonym of 'box' % % To draw a box with width and height % x1 y1 w h rbox fill/stroke % % To draw a box with center coordinates, width and height % cx1 cy1 w h cbox fill/stroke % % To draw a round-corner rectangle % x1 y1 x2 y2 corner_size roundrect % % To draw a parallelo % x1 y1 x2 y2 dx parallelo fill/stroke % % To draw a circle % x1 y1 rad circle fill/stroke % % To draw an ellipse % x1 y1 a b ellipse fill/stroke % % To draw a bent curve connecing two lines % x1 y1 x2 y2 x3 y3 x4 y4 r bendto % r: 0 - 1 % % To draw a rectangular lattice % x1 y1 x2 y2 width lattice % Calc average xM, yM from x1, y1 and x2, y2 /average{ exch 4 3 roll add 2 div 3 1 roll add 2 div } def /line{ moveto lineto stroke }def /path{ moveto count 2 div cvi {lineto} repeat }def /griddic 1 dict def /grid { griddic begin currentlinewidth /lw exch def currentrgbcolor 3 array astore /rgb exch def /sep exch def /sep5 {sep 5 mul} def /y2 exch def /x2 exch def /y1 exch def /x1 exch def 0.1 setlinewidth 0.4 1.0 0.7 setrgbcolor x1 sep x2{ dup y1 exch y2 moveto lineto stroke }for y1 sep y2 { dup x1 3 1 roll x2 exch moveto lineto stroke }for 0.5 setlinewidth 0 0.8 0.2 setrgbcolor x1 sep5 x2{ dup y1 exch y2 moveto lineto stroke }for y1 sep5 y2 { dup x1 3 1 roll x2 exch moveto lineto stroke }for lw setlinewidth rgb aload pop setrgbcolor end } def % define box /boxdict 1 dict def /box { boxdict begin /y2 exch def /x2 exch def /y1 exch def /x1 exch def x1 y1 x2 y1 x2 y2 x1 y2 moveto lineto lineto lineto closepath end } def % define box with xL, yD, width, height /rboxdict 1 dict def /rbox { rboxdict begin /h exch def /w exch def /y1 exch def /x1 exch def x1 y1 moveto w 0 rlineto 0 h rlineto w neg 0 rlineto closepath end } def % define box with center x y and width, height /cboxdict 1 dict def /cbox { rboxdict begin /h exch def /w exch def /y1 exch def /x1 exch def x1 w 0.5 mul sub y1 h 0.5 mul sub moveto w 0 rlineto 0 h rlineto w neg 0 rlineto closepath end } def /rect { box }def /rrect { rbox }def /crect { cbox }def % define parallelo /trapdic 1 dict def /parallelo { trapdic begin /dy exch def /dx exch def /y2 exch def /x2 exch def /y1 exch def /x1 exch def x1 y1 moveto x2 dx sub y1 dy add lineto x2 y2 lineto x1 dx add y2 dy sub lineto closepath end } def /circle{ 0 360 arc } def /ellipse { newpath 4 2 roll 2 copy neg exch neg exch 6 2 roll translate 2 copy exch div 1 exch scale exch dup 0 0 3 2 roll 0 360 arc exch div 1 exch scale translate }def /bendtodict 1 dict def /bendto{ bendtodict begin /r1 exch def /y3 exch def /x3 exch def /y4 exch def /x4 exch def /y2 exch def /x2 exch def /y1 exch def /x1 exch def % x1 y1 x2 y2 x4 y4 x3 y3 path s /a {x2 x1 sub} def /b {y2 y1 sub} def /c {x4 x3 sub} def /d {y4 y3 sub} def /det {b c mul a d mul sub}def /x {b c x2 mul mul a c y2 mul mul sub a d x4 mul mul sub a c y4 mul mul add det div} def /y {b d x2 mul mul a d y2 mul mul sub b d x4 mul mul sub b c y4 mul mul add det div} def /r2 {1 r1 sub} def /rx1 {x2 r1 mul x r2 mul add} def /ry1 {y2 r1 mul y r2 mul add} def /rx2 {x4 r1 mul x r2 mul add} def /ry2 {y4 r1 mul y r2 mul add} def x1 y1 moveto x2 y2 lineto rx1 ry1 lineto x y rx2 ry2 x4 y4 curveto x3 y3 lineto stroke end }def /rndrectdict 1 dict def /roundrect { rndrectdict begin /rc exch def /y2 exch def /x2 exch def /y1 exch def /x1 exch def /rch{rc 0.5 mul}def x1 x2 add 2 div y1 m x2 rc sub y1 lineto x2 rch sub y1 x2 y1 rch add x2 y1 rc add curveto x2 y2 rc sub lineto x2 y2 rch sub x2 rch sub y2 x2 rc sub y2 curveto x1 rc add y2 lineto x1 rch add y2 x1 y2 rch sub x1 y2 rc sub curveto x1 y1 rc add lineto x1 y1 rch add x1 rch add y1 x1 rc add y1 curveto closepath end } def /crndrectdict 1 dict def /croundrect { rndrectdict begin /rc exch def /height1 exch def /width1 exch def /yc exch def /xc exch def /rch{rc 0.5 mul}def /x1{xc width1 2 div sub} def /y1{yc height1 2 div sub} def /x2{xc width1 2 div add} def /y2{yc height1 2 div add} def x1 x2 add 2 div y1 m x2 rc sub y1 lineto x2 rch sub y1 x2 y1 rch add x2 y1 rc add curveto x2 y2 rc sub lineto x2 y2 rch sub x2 rch sub y2 x2 rc sub y2 curveto x1 rc add y2 lineto x1 rch add y2 x1 y2 rch sub x1 y2 rc sub curveto x1 y1 rc add lineto x1 y1 rch add x1 rch add y1 x1 rc add y1 curveto closepath end } def /latticedic 1 dict def /lattice { latticedic begin currentlinewidth /lw exch def /sep exch def /y2 exch def /x2 exch def /y1 exch def /x1 exch def 0.4 setlinewidth x1 sep x2{ dup y1 exch y2 moveto lineto stroke }for y1 sep y2 { dup x1 3 1 roll x2 exch moveto lineto stroke }for lw setlinewidth end } def