You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.2 KiB

  1. <?php
  2. $pdffilename = "clock.pdf";
  3. $radius = 200;
  4. $margin = 20;
  5. $pagecount = 99;
  6. $pdf = cpdf_open(0);
  7. cpdf_set_creator($pdf, "pdf_clock.php3");
  8. cpdf_set_title($pdf, "Analog Clock");
  9. while($pagecount-- > 0) {
  10. cpdf_page_init($pdf, $pagecount+1, 0, 2 * ($radius + $margin), 2 * ($radius + $margin), 1.0);
  11. cpdf_set_page_animation($pdf, 4, 0.5, 0, 0, 0); /* wipe */
  12. cpdf_translate($pdf, $radius + $margin, $radius + $margin);
  13. cpdf_save($pdf);
  14. cpdf_setrgbcolor($pdf, 0.0, 0.0, 1.0);
  15. /* minute strokes */
  16. cpdf_setlinewidth($pdf, 2.0);
  17. for ($alpha = 0; $alpha < 360; $alpha += 6)
  18. {
  19. cpdf_rotate($pdf, 6.0);
  20. cpdf_moveto($pdf, $radius, 0.0);
  21. cpdf_lineto($pdf, $radius-$margin/3, 0.0);
  22. cpdf_stroke($pdf);
  23. }
  24. cpdf_restore($pdf);
  25. cpdf_save($pdf);
  26. /* 5 minute strokes */
  27. cpdf_setlinewidth($pdf, 3.0);
  28. for ($alpha = 0; $alpha < 360; $alpha += 30)
  29. {
  30. cpdf_rotate($pdf, 30.0);
  31. cpdf_moveto($pdf, $radius, 0.0);
  32. cpdf_lineto($pdf, $radius-$margin, 0.0);
  33. cpdf_stroke($pdf);
  34. }
  35. $ltime = getdate();
  36. /* draw hour hand */
  37. cpdf_save($pdf);
  38. cpdf_rotate($pdf, -(($ltime['minutes']/60.0) + $ltime['hours'] - 3.0) * 30.0);
  39. cpdf_moveto($pdf, -$radius/10, -$radius/20);
  40. cpdf_lineto($pdf, $radius/2, 0.0);
  41. cpdf_lineto($pdf, -$radius/10, $radius/20);
  42. cpdf_closepath($pdf);
  43. cpdf_fill($pdf);
  44. cpdf_restore($pdf);
  45. /* draw minute hand */
  46. cpdf_save($pdf);
  47. cpdf_rotate($pdf, -(($ltime['seconds']/60.0) + $ltime['minutes'] - 15.0) * 6.0);
  48. cpdf_moveto($pdf, -$radius/10, -$radius/20);
  49. cpdf_lineto($pdf, $radius * 0.8, 0.0);
  50. cpdf_lineto($pdf, -$radius/10, $radius/20);
  51. cpdf_closepath($pdf);
  52. cpdf_fill($pdf);
  53. cpdf_restore($pdf);
  54. /* draw second hand */
  55. cpdf_setrgbcolor($pdf, 1.0, 0.0, 0.0);
  56. cpdf_setlinewidth($pdf, 2);
  57. cpdf_save($pdf);
  58. cpdf_rotate($pdf, -(($ltime['seconds'] - 15.0) * 6.0));
  59. cpdf_moveto($pdf, -$radius/5, 0.0);
  60. cpdf_lineto($pdf, $radius, 0.0);
  61. cpdf_stroke($pdf);
  62. cpdf_restore($pdf);
  63. /* draw little circle at center */
  64. cpdf_circle($pdf, 0, 0, $radius/30);
  65. cpdf_fill($pdf);
  66. cpdf_restore($pdf);
  67. cpdf_finalize_page($pdf, $pagecount+1);
  68. }
  69. cpdf_finalize($pdf);
  70. cpdf_save_to_file($pdf, $pdffilename);
  71. $pdf = cpdf_close($pdf);
  72. ?>