wps

PostScript for the Web
git clone https://logand.com/git/wps.git/
Log | Files | Refs | LICENSE

clock2.wps (1752B)


      1 % based on the PostScript example from
      2 % http://oreilly.com/openbook/cgi/ch06_02.html
      3 
      4 0 0 150 150 .gbox
      5 0 150 translate
      6 1 -1 scale
      7 
      8 /max      150 def
      9 /width    1.5 def
     10 /marker   5 def
     11 /origin   {0 0} def
     12 /center   {max 2 div} bind def
     13 /radius   /center load def
     14 /hsegment 0.50 radius mul def
     15 /msegment 0.80 radius mul def
     16 /ssegment 0.90 radius mul def
     17 
     18 /yellow {1 1 0 setrgbcolor} bind def
     19 /red    {1 0 0 setrgbcolor} bind def
     20 /green  {0 1 0 setrgbcolor} bind def
     21 /blue   {0 0 1 setrgbcolor} bind def
     22 /black  {0 0 0 setrgbcolor} bind def
     23 
     24 /hangle {/$h load 60 mul /$m load add 2 div neg .deg2rad} bind def
     25 /mangle {/$m load 6 mul neg .deg2rad} bind def
     26 /sangle {/$s load 6 mul neg .deg2rad} bind def
     27 
     28 /hand { % segment angle color width --
     29   origin moveto
     30   width mul setlinewidth
     31   load exec
     32   2 copy   cos mul
     33   3 1 roll sin mul
     34   lineto stroke
     35 } bind def
     36 
     37 /draw {
     38   /$h .date (getHours)   0 .call def
     39   /$m .date (getMinutes) 0 .call def
     40   /$s .date (getSeconds) 0 .call def
     41   gsave
     42   width setlinewidth
     43   black clippath fill % background
     44   center dup translate
     45   90 rotate
     46   gsave % markers
     47   12 {
     48     radius marker sub 0 moveto 
     49     marker 0 rlineto red stroke
     50     360 12 div rotate
     51   } repeat
     52   grestore
     53   newpath origin radius 0 360 arc blue stroke % circle
     54   hsegment hangle /green  2   hand % hour
     55   msegment mangle /green  1   hand % minute
     56   ssegment sangle /yellow 0.5 hand % second
     57   origin width 2 mul 0 360 arc red fill % dot
     58   grestore
     59 } bind def
     60 
     61 draw
     62 
     63 /timer    false def
     64 /go       {{draw} .callback 1000 .setInterval /timer exch def} bind def
     65 /halt     {/timer load .clearTimeout /timer false def} bind def
     66 /callback {/timer load type (booleantype) eq {go} {halt} ifelse} bind def
     67 
     68 .gcanvas (onclick) /callback load .callback .hook