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.
 
 
 
 
 
 

70 lines
1.8 KiB

  1. #!/usr/bin/php5
  2. <?php
  3. $pig_str = <<<EOT
  4. _._ _..._ .-', _.._(`))
  5. '-. ` ' /-._.-' ',/
  6. ) \ '.
  7. / _ _ | \
  8. | a a / PHP |
  9. \ .-. ;
  10. '-('' ).-' ,' ;
  11. '-; | .'
  12. \ \ /
  13. | 7 .__ _.-\ \
  14. | | | ``/ /` /
  15. jgs /,_| | /,_/ /
  16. /,_/ '`-'
  17. EOT;
  18. $canvas = caca_create_canvas(0, 0);
  19. if (!$canvas) {
  20. die("Error while creating main canvas\n");
  21. }
  22. $pig = caca_create_canvas(0, 0);
  23. if (!$pig) {
  24. die("Error while creating canvas pig\n");
  25. }
  26. $display = caca_create_display($canvas);
  27. if (!$display) {
  28. die("Error while attaching canvas to display\n");
  29. }
  30. caca_set_color_ansi($pig, CACA_LIGHTMAGENTA, CACA_TRANSPARENT);
  31. caca_set_color_ansi($canvas, CACA_LIGHTBLUE, CACA_TRANSPARENT);
  32. caca_import_string($pig, $pig_str, "text");
  33. caca_set_display_time($display, 30000);
  34. $x = $y = 0;
  35. $ix = $iy = 1;
  36. while (!caca_get_event($display, CACA_EVENT_KEY_PRESS)) {
  37. // In case of resize ...
  38. if ($x + caca_get_canvas_width($pig) - 1 >= caca_get_canvas_width($canvas) || $x < 0 )
  39. $x = 0;
  40. if ($y + caca_get_canvas_height($pig) - 1 >= caca_get_canvas_height($canvas) || $y < 0 )
  41. $y = 0;
  42. caca_clear_canvas($canvas);
  43. // Draw
  44. caca_blit($canvas, $x, $y, $pig);
  45. caca_put_str($canvas, caca_get_canvas_width($canvas) / 2 - 10, caca_get_canvas_height($canvas) / 2, "Powered by libcaca ".caca_get_version());
  46. caca_refresh_display($display);
  47. // Move cursor
  48. $x += $ix;
  49. $y += $iy;
  50. if ($x + caca_get_canvas_width($pig) >= caca_get_canvas_width($canvas) || $x < 0 )
  51. $ix = -$ix;
  52. if ($y + caca_get_canvas_height($pig) >= caca_get_canvas_height($canvas) || $y < 0 )
  53. $iy = -$iy;
  54. }
  55. ?>