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.

пре 16 година
пре 16 година
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/php5
  2. <?php
  3. /*
  4. * cacapig.php sample program for libcaca php binding
  5. * Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
  6. *
  7. * This file is a Php port of "cxx/cpptest.cpp"
  8. * which is:
  9. * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
  10. * All Rights Reserved
  11. *
  12. * This program is free software. It comes without any warranty, to
  13. * the extent permitted by applicable law. You can redistribute it
  14. * and/or modify it under the terms of the Do What The Fuck You Want
  15. * To Public License, Version 2, as published by Sam Hocevar. See
  16. * http://sam.zoy.org/wtfpl/COPYING for more details.
  17. */
  18. if (php_sapi_name() != "cli") {
  19. die("You have to run this program with php-cli!\n");
  20. }
  21. $pig_str = <<<EOT
  22. _._ _..._ .-', _.._(`))
  23. '-. ` ' /-._.-' ',/
  24. ) \ '.
  25. / _ _ | \
  26. | a a / PHP |
  27. \ .-. ;
  28. '-('' ).-' ,' ;
  29. '-; | .'
  30. \ \ /
  31. | 7 .__ _.-\ \
  32. | | | ``/ /` /
  33. jgs /,_| | /,_/ /
  34. /,_/ '`-'
  35. EOT;
  36. $canvas = caca_create_canvas(0, 0);
  37. if (!$canvas) {
  38. die("Error while creating main canvas\n");
  39. }
  40. $pig = caca_create_canvas(0, 0);
  41. if (!$pig) {
  42. die("Error while creating canvas pig\n");
  43. }
  44. $display = caca_create_display($canvas);
  45. if (!$display) {
  46. die("Error while attaching canvas to display\n");
  47. }
  48. caca_set_color_ansi($pig, CACA_LIGHTMAGENTA, CACA_TRANSPARENT);
  49. caca_set_color_ansi($canvas, CACA_LIGHTBLUE, CACA_TRANSPARENT);
  50. caca_import_string($pig, $pig_str, "text");
  51. caca_set_display_time($display, 30000);
  52. $x = $y = 0;
  53. $ix = $iy = 1;
  54. while (!caca_get_event($display, CACA_EVENT_KEY_PRESS)) {
  55. // In case of resize ...
  56. if ($x + caca_get_canvas_width($pig) - 1 >= caca_get_canvas_width($canvas) || $x < 0 )
  57. $x = 0;
  58. if ($y + caca_get_canvas_height($pig) - 1 >= caca_get_canvas_height($canvas) || $y < 0 )
  59. $y = 0;
  60. caca_clear_canvas($canvas);
  61. // Draw
  62. caca_blit($canvas, $x, $y, $pig);
  63. caca_put_str($canvas, caca_get_canvas_width($canvas) / 2 - 10, caca_get_canvas_height($canvas) / 2, "Powered by libcaca ".caca_get_version());
  64. caca_refresh_display($display);
  65. // Move cursor
  66. $x += $ix;
  67. $y += $iy;
  68. if ($x + caca_get_canvas_width($pig) >= caca_get_canvas_width($canvas) || $x < 0 )
  69. $ix = -$ix;
  70. if ($y + caca_get_canvas_height($pig) >= caca_get_canvas_height($canvas) || $y < 0 )
  71. $iy = -$iy;
  72. }
  73. ?>