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 / python / pdfclock.py < prev    next >
Encoding:
Python Source  |  2001-07-04  |  2.0 KB  |  92 lines  |  [TEXT/Pyth]

  1. #!/usr/bin/python
  2. # $Id: pdfclock.py,v 1.6.2.1 2001/05/16 12:25:50 york Exp $
  3. #
  4. # PDFlib client: pdfclock example in Python
  5. #
  6.  
  7. from sys import *
  8. from time import *
  9. from pdflib_py import *
  10.  
  11. RADIUS = 200.0
  12. MARGIN = 20.0
  13.  
  14. p = PDF_new()
  15.  
  16. if PDF_open_file(p, "pdfclock.pdf") == -1:
  17.     print "Couldn't open PDF file 'pdfclock.pdf'\n"
  18.     exit(2)
  19.  
  20. PDF_set_info(p, "Author", "Thomas Merz")
  21. PDF_set_info(p, "Creator", "pdfclock.py")
  22. PDF_set_info(p, "Title", "PDF clock (Python)")
  23.  
  24. PDF_begin_page(p, 2 * (RADIUS + MARGIN), 2 * (RADIUS + MARGIN))
  25.  
  26. PDF_translate(p, RADIUS + MARGIN, RADIUS + MARGIN)
  27. PDF_setcolor(p, "both", "rgb", 0.0, 0.0, 1.0, 0.0)
  28. PDF_save(p)
  29.  
  30. # minute strokes 
  31. PDF_setlinewidth(p, 2.0)
  32. for alpha in range(0, 360, 6):
  33.     PDF_rotate(p, 6.0)
  34.     PDF_moveto(p, RADIUS, 0.0)
  35.     PDF_lineto(p, RADIUS-MARGIN/3, 0.0)
  36.     PDF_stroke(p)
  37.  
  38. PDF_restore(p)
  39. PDF_save(p)
  40.  
  41. # 5 minute strokes
  42. PDF_setlinewidth(p, 3.0)
  43. for alpha in range(0, 360, 30):
  44.     PDF_rotate(p, 30.0)
  45.     PDF_moveto(p, RADIUS, 0.0)
  46.     PDF_lineto(p, RADIUS-MARGIN, 0.0)
  47.     PDF_stroke(p)
  48.  
  49. (tm_year, tm_month, tm_day,
  50. tm_hour, tm_min, tm_sec, 
  51. tm_weekday, tm_julian, tm_ds) = localtime(time())
  52.  
  53. # draw hour hand 
  54. PDF_save(p)
  55. PDF_rotate(p, (-((tm_min/60.0) + tm_hour - 3.0) * 30.0))
  56. PDF_moveto(p, -RADIUS/10, -RADIUS/20)
  57. PDF_lineto(p, RADIUS/2, 0.0)
  58. PDF_lineto(p, -RADIUS/10, RADIUS/20)
  59. PDF_closepath(p)
  60. PDF_fill(p)
  61. PDF_restore(p)
  62.  
  63. # draw minute hand
  64. PDF_save(p)
  65. PDF_rotate(p, (-((tm_sec/60.0) + tm_min - 15.0) * 6.0))
  66. PDF_moveto(p, -RADIUS/10, -RADIUS/20)
  67. PDF_lineto(p, RADIUS * 0.8, 0.0)
  68. PDF_lineto(p, -RADIUS/10, RADIUS/20)
  69. PDF_closepath(p)
  70. PDF_fill(p)
  71. PDF_restore(p)
  72.  
  73. # draw second hand
  74. PDF_setcolor(p, "both", "rgb", 1.0, 0.0, 0.0, 0.0)
  75. PDF_setlinewidth(p, 2)
  76. PDF_save(p)
  77. PDF_rotate(p, -((tm_sec - 15.0) * 6.0))
  78. PDF_moveto(p, -RADIUS/5, 0.0)
  79. PDF_lineto(p, RADIUS, 0.0)
  80. PDF_stroke(p)
  81. PDF_restore(p)
  82.  
  83. # draw little circle at center
  84. PDF_circle(p, 0, 0, RADIUS/30)
  85. PDF_fill(p)
  86.  
  87. PDF_restore(p)
  88. PDF_end_page(p)
  89.  
  90. PDF_close(p)
  91. PDF_delete(p)
  92.