25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

cacapig.php 2.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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/cxxtest.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. include dirname($argv[0]) . '/../caca.php';
  22. $pig_str = <<<EOT
  23. _._ _..._ .-', _.._(`))
  24. '-. ` ' /-._.-' ',/
  25. ) \ '.
  26. / _ _ | \
  27. | a a / PHP |
  28. \ .-. ;
  29. '-('' ).-' ,' ;
  30. '-; | .'
  31. \ \ /
  32. | 7 .__ _.-\ \
  33. | | | ``/ /` /
  34. jgs /,_| | /,_/ /
  35. /,_/ '`-'
  36. EOT;
  37. $canvas = new Canvas();
  38. if (!$canvas) {
  39. die("Error while creating main canvas\n");
  40. }
  41. $pig = new Canvas();
  42. if (!$pig) {
  43. die("Error while creating canvas pig\n");
  44. }
  45. $display = new Display($canvas);
  46. if (!$display) {
  47. die("Error while attaching canvas to display\n");
  48. }
  49. $pig->setColorANSI(AnsiColor::LIGHTMAGENTA, AnsiColor::TRANSPARENT);
  50. $pig->importString($pig_str, "text");
  51. $display->setDisplayTime(20000);
  52. $x = $y = 0;
  53. $ix = $iy = 1;
  54. while (! $display->getEvent(EventType::KEY_PRESS)) {
  55. // In case of resize ...
  56. if ($x + $pig->getWidth() - 1 >= $canvas->getWidth() || $x < 0 )
  57. $x = 0;
  58. if ($y + $pig->getHeight() - 1 >= $canvas->getHeight() || $y < 0 )
  59. $y = 0;
  60. $canvas->Clear();
  61. // Draw
  62. $canvas->Blit($x, $y, $pig, NULL);
  63. $canvas->setColorANSI(AnsiColor::LIGHTBLUE, AnsiColor::BLACK);
  64. $canvas->putStr($canvas->getWidth() / 2 - 10, $canvas->getHeight() / 2, "Powered by libcaca ".Libcaca::getVersion());
  65. $display->refresh();
  66. // Move cursor
  67. $x += $ix;
  68. $y += $iy;
  69. if ($x + $pig->getWidth() >= $canvas->getWidth() || $x < 0 )
  70. $ix = -$ix;
  71. if ($y + $pig->getHeight() >= $canvas->getHeight() || $y < 0 )
  72. $iy = -$iy;
  73. }
  74. ?>