選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

86 行
2.4 KiB

  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. $pig_str = <<<EOT
  19. _._ _..._ .-', _.._(`))
  20. '-. ` ' /-._.-' ',/
  21. ) \ '.
  22. / _ _ | \
  23. | a a / PHP |
  24. \ .-. ;
  25. '-('' ).-' ,' ;
  26. '-; | .'
  27. \ \ /
  28. | 7 .__ _.-\ \
  29. | | | ``/ /` /
  30. jgs /,_| | /,_/ /
  31. /,_/ '`-'
  32. EOT;
  33. $canvas = caca_create_canvas(0, 0);
  34. if (!$canvas) {
  35. die("Error while creating main canvas\n");
  36. }
  37. $pig = caca_create_canvas(0, 0);
  38. if (!$pig) {
  39. die("Error while creating canvas pig\n");
  40. }
  41. $display = caca_create_display($canvas);
  42. if (!$display) {
  43. die("Error while attaching canvas to display\n");
  44. }
  45. caca_set_color_ansi($pig, CACA_LIGHTMAGENTA, CACA_TRANSPARENT);
  46. caca_set_color_ansi($canvas, CACA_LIGHTBLUE, CACA_TRANSPARENT);
  47. caca_import_string($pig, $pig_str, "text");
  48. caca_set_display_time($display, 30000);
  49. $x = $y = 0;
  50. $ix = $iy = 1;
  51. while (!caca_get_event($display, CACA_EVENT_KEY_PRESS)) {
  52. // In case of resize ...
  53. if ($x + caca_get_canvas_width($pig) - 1 >= caca_get_canvas_width($canvas) || $x < 0 )
  54. $x = 0;
  55. if ($y + caca_get_canvas_height($pig) - 1 >= caca_get_canvas_height($canvas) || $y < 0 )
  56. $y = 0;
  57. caca_clear_canvas($canvas);
  58. // Draw
  59. caca_blit($canvas, $x, $y, $pig);
  60. caca_put_str($canvas, caca_get_canvas_width($canvas) / 2 - 10, caca_get_canvas_height($canvas) / 2, "Powered by libcaca ".caca_get_version());
  61. caca_refresh_display($display);
  62. // Move cursor
  63. $x += $ix;
  64. $y += $iy;
  65. if ($x + caca_get_canvas_width($pig) >= caca_get_canvas_width($canvas) || $x < 0 )
  66. $ix = -$ix;
  67. if ($y + caca_get_canvas_height($pig) >= caca_get_canvas_height($canvas) || $y < 0 )
  68. $iy = -$iy;
  69. }
  70. ?>