home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 February / PCWorld_2002-02_cd.bin / Software / Vyzkuste / pdflib / pdflib-4.0.1.sit / pdflib-4.0.1 / bind / tcl / pdfclock.tcl < prev    next >
Encoding:
Text File  |  2001-07-04  |  2.7 KB  |  110 lines  |  [TEXT/WIsH]

  1. #!/bin/sh
  2. # $Id: pdfclock.tcl,v 1.9.2.1 2001/05/16 12:25:50 york Exp $
  3. #
  4. # PDFlib client: pdfclock example in Tcl
  5. #
  6.  
  7. # Hide the exec to Tcl but not to the shell by appending a backslash\
  8. exec tclsh "$0" ${1+"$@"}
  9.  
  10. # The lappend line is unnecessary if PDFlib has been installed
  11. # in the Tcl package directory
  12. set auto_path [linsert $auto_path 0 .libs .]
  13.  
  14. package require pdflib 4.0
  15.  
  16. set RADIUS 200.0
  17. set MARGIN 20.0
  18.  
  19. set p [PDF_new]
  20.  
  21. if {[PDF_open_file $p "pdfclock.pdf"] == -1} {
  22.     puts stderr "Couldn't open PDF file!"
  23. }
  24.  
  25.  
  26. PDF_set_info $p "Creator" "pdfclock.tcl"
  27. PDF_set_info $p "Author" "Thomas Merz"
  28. PDF_set_info $p "Title" "PDF clock (Tcl)"
  29.  
  30. PDF_begin_page $p [expr 2 * ($RADIUS + $MARGIN)] [expr  2 * ($RADIUS + $MARGIN)]
  31.  
  32. PDF_translate $p [expr $RADIUS + $MARGIN] [expr $RADIUS + $MARGIN]
  33. PDF_setcolor $p "both" "rgb" 0.0 0.0 1.0 0.0
  34. PDF_save $p
  35.  
  36. # minute strokes
  37. PDF_setlinewidth $p 2.0
  38. for {set alpha  0} {$alpha < 360} {set alpha [expr $alpha + 6]} {
  39.     PDF_rotate $p 6.0
  40.     PDF_moveto $p $RADIUS 0.0
  41.     PDF_lineto $p [expr $RADIUS-$MARGIN/3] 0.0
  42.     PDF_stroke $p
  43. }
  44.  
  45. PDF_restore $p
  46. PDF_save $p
  47.  
  48. # 5 minute strokes
  49. PDF_setlinewidth $p 3.0
  50. for {set alpha  0} {$alpha < 360} {set alpha [expr $alpha + 30]} {
  51.     PDF_rotate $p 30.0
  52.     PDF_moveto $p $RADIUS 0.0
  53.     PDF_lineto $p [expr $RADIUS-$MARGIN] 0.0
  54.     PDF_stroke $p
  55. }
  56.  
  57. set tm_hour [ clock format [clock seconds] -format "%I" ]
  58. set tm_min  [ clock format [clock seconds] -format "%M" ]
  59. set tm_sec  [ clock format [clock seconds] -format "%S" ]
  60.  
  61. # This is a Tcl-itis: when the clock returns "08" seconds, tm_sec
  62. # won't be recognized as an integer. Therefore we "cast" it to integer.
  63. # Note that this doesn't happen with, for example, the value "07"
  64. # because this is a valid octal number...
  65.  
  66. scan $tm_hour %d tm_hour 
  67. scan $tm_min  %d tm_min 
  68. scan $tm_sec  %d tm_sec 
  69.  
  70. # draw hour hand
  71. PDF_save $p
  72. PDF_rotate $p [expr -(($tm_min/60.0) + $tm_hour - 3.0) * 30.0]
  73. PDF_moveto $p [expr -$RADIUS/10] [expr -$RADIUS/20]
  74. PDF_lineto $p [expr $RADIUS/2] 0.0
  75. PDF_lineto $p [expr -$RADIUS/10] [expr $RADIUS/20]
  76. PDF_closepath $p
  77. PDF_fill $p
  78. PDF_restore $p
  79.  
  80. # draw minute hand
  81. PDF_save $p
  82. PDF_rotate $p [expr -(($tm_sec/60.0) + $tm_min - 15.0) * 6.0]
  83. PDF_moveto $p [expr -$RADIUS/10] [expr -$RADIUS/20]
  84. PDF_lineto $p [expr $RADIUS * 0.8] 0.0
  85. PDF_lineto $p [expr -$RADIUS/10] [expr $RADIUS/20]
  86. PDF_closepath $p
  87. PDF_fill $p
  88. PDF_restore $p
  89.  
  90. # draw second hand
  91. PDF_setcolor $p "both" "rgb" 1.0 0.0 0.0 0.0
  92. PDF_setlinewidth $p 2
  93. PDF_save $p
  94. PDF_rotate $p [expr -(($tm_sec - 15.0) * 6.0)]
  95. PDF_moveto $p [expr -$RADIUS/5] 0.0
  96. PDF_lineto $p $RADIUS 0.0
  97. PDF_stroke $p
  98. PDF_restore $p
  99.  
  100. # draw little circle at center
  101. PDF_circle $p 0 0 [expr $RADIUS/30]
  102. PDF_fill $p
  103.  
  104. PDF_restore $p
  105.  
  106. PDF_end_page $p
  107. PDF_close $p
  108.  
  109. PDF_delete $p
  110.