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