home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / php / pear / docs / ps / examples / .tmppsclock.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  2.3 KB  |  105 lines

  1. <?php
  2. $radius = 200;
  3. $margin = 20;
  4. $pagecount = 300;
  5.  
  6. $ps = ps_new();
  7.  
  8. if (!ps_open_file($ps, "psclock.ps")) {
  9.     print "Cannot open PostScript file\n";
  10.     exit;
  11. }
  12.  
  13. ps_set_parameter($ps, "warning", "true");
  14.  
  15. ps_set_info($ps, "Creator", "psclock.php");
  16. ps_set_info($ps, "Author", "Uwe Steinmann");
  17. ps_set_info($ps, "Title", "Analog Clock");
  18.  
  19. while($pagecount-- > 0) {
  20.     ps_begin_page($ps, 2 * ($radius + $margin), 2 * ($radius + $margin));
  21.  
  22.     ps_set_parameter($ps, "transition", "wipe");
  23.     ps_set_value($ps, "duration", 0.5);
  24.  
  25.     ps_translate($ps, $radius + $margin, $radius + $margin);
  26.     ps_save($ps);
  27.     ps_setrgbcolor($ps, 0.0, 0.0, 1.0);
  28.  
  29.     /* minute strokes */
  30.     ps_setlinewidth($ps, 2.0);
  31.     for ($alpha = 0; $alpha < 360; $alpha += 6) {
  32.         ps_rotate($ps, 6.0);
  33.         ps_moveto($ps, $radius, 0.0);
  34.         ps_lineto($ps, $radius-$margin/3, 0.0);
  35.         ps_stroke($ps);
  36.     }
  37.  
  38.     ps_restore($ps);
  39.     ps_save($ps);
  40.  
  41.     /* 5 minute strokes */
  42.     ps_setlinewidth($ps, 3.0);
  43.     for ($alpha = 0; $alpha < 360; $alpha += 30) { 
  44.         ps_rotate($ps, 30.0);
  45.         ps_moveto($ps, $radius, 0.0);
  46.         ps_lineto($ps, $radius-$margin, 0.0);
  47.         ps_stroke($ps);
  48.     }
  49.  
  50.     $ltime = getdate();
  51.  
  52.     /* draw hour hand */
  53.     ps_restore($ps);
  54.     ps_save($ps);
  55.     ps_rotate($ps,-(($ltime['minutes']/60.0)+$ltime['hours']-3.0)*30.0);
  56.     ps_moveto($ps, -$radius/10, -$radius/20);
  57.     ps_lineto($ps, $radius/2, 0.0);
  58.     ps_lineto($ps, -$radius/10, $radius/20);
  59.     ps_closepath($ps);
  60.     ps_fill($ps);
  61.     ps_restore($ps);
  62.  
  63.     /* draw minute hand */
  64.     ps_save($ps);
  65.     ps_rotate($ps,-(($ltime['seconds']/60.0)+$ltime['minutes']-15.0)*6.0);
  66.     ps_moveto($ps, -$radius/10, -$radius/20);
  67.     ps_lineto($ps, $radius * 0.8, 0.0);
  68.     ps_lineto($ps, -$radius/10, $radius/20);
  69.     ps_closepath($ps);
  70.     ps_fill($ps);
  71.     ps_restore($ps);
  72.  
  73.     /* draw second hand */
  74. //    ps_setrgbcolor($ps, 1.0, 0.0, 0.0);
  75.     ps_setlinewidth($ps, 2);
  76.     ps_save($ps);
  77.     ps_rotate($ps, -(($ltime['seconds'] - 15.0) * 6.0));
  78.     ps_moveto($ps, -$radius/5, 0.0);
  79.     ps_lineto($ps, $radius, 0.0);
  80.     ps_stroke($ps);
  81.     ps_restore($ps);
  82.  
  83.     /* draw little circle at center */
  84.     ps_circle($ps, 0, 0, $radius/30);
  85.     ps_fill($ps);
  86.  
  87.     ps_end_page($ps);
  88.  
  89.     # to see some difference
  90. //    sleep(1);
  91. }
  92.  
  93. /*$buf = ps_get_buffer($ps);
  94. $len = strlen($buf);
  95.  
  96. header("Content-type: application/pdf");
  97. header("Content-Length: $len");
  98. header("Content-Disposition: inline; filename=foo.pdf");
  99. print $buf;
  100. */
  101.  
  102. ps_close($ps);
  103. ps_delete($ps);
  104. ?>
  105.