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.

transform.php 2.9 KiB

16 jaren geleden
16 jaren geleden
16 jaren geleden
16 jaren geleden
16 jaren geleden
16 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/php5
  2. <?php
  3. /*
  4. * transform transformation test program
  5. * Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
  6. *
  7. * This file is a Php port of "examples/transform.c"
  8. * which is:
  9. * Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
  10. * All Rights Reserved
  11. *
  12. * $Id$
  13. *
  14. * This program is free software. It comes without any warranty, to
  15. * the extent permitted by applicable law. You can redistribute it
  16. * and/or modify it under the terms of the Do What The Fuck You Want
  17. * To Public License, Version 2, as published by Sam Hocevar. See
  18. * http://sam.zoy.org/wtfpl/COPYING for more details.
  19. */
  20. if (php_sapi_name() != "cli") {
  21. die("You have to run this program with php-cli!\n");
  22. }
  23. $pig = (
  24. ",--. ,--.\n" .
  25. "\\ /-~-\\ /\n" .
  26. " )' o O `(\n" .
  27. "( ,---. )\n" .
  28. " `(_o_o_)'\n" .
  29. " )`-'(\n");
  30. $duck = (
  31. " ,~~.\n" .
  32. " __ , ( O )>\n" .
  33. "___( o)> )`~~' (\n" .
  34. "\\ <_. ) ( .__) )\n" .
  35. " `---' `-.____,'\n");
  36. $cv = caca_create_canvas(0, 0);
  37. if(! $cv)
  38. {
  39. die("Can't created canvas\n");
  40. }
  41. $dp = caca_create_display($cv);
  42. if(! $dp)
  43. {
  44. die("Can't create display\n");
  45. }
  46. $image = caca_create_canvas(70, 6);
  47. $tmp = caca_create_canvas(70, 6);
  48. $sprite = caca_create_canvas(0, 0);
  49. caca_set_color_ansi($sprite, CACA_LIGHTMAGENTA, CACA_BLACK);
  50. caca_import_string($sprite, $pig, "text");
  51. caca_blit($image, 55, 0, $sprite);
  52. caca_set_color_ansi($sprite, CACA_LIGHTGREEN, CACA_BLACK);
  53. caca_import_string($sprite, $duck, "text");
  54. caca_blit($image, 30, 1, $sprite);
  55. caca_set_color_ansi($image, CACA_LIGHTCYAN, CACA_BLACK);
  56. caca_put_str($image, 1, 1, "hahaha mais vieux porc immonde !! [⽼ ⾗]");
  57. caca_set_color_ansi($image, CACA_LIGHTRED, CACA_BLACK);
  58. caca_put_char($image, 38, 1, ord('|'));
  59. caca_set_color_ansi($image, CACA_YELLOW, CACA_BLACK);
  60. caca_put_str($image, 4, 2, "\\o\\ \\o| _o/ \\o_ |o/ /o/");
  61. caca_set_color_ansi($image, CACA_WHITE, CACA_LIGHTRED);
  62. caca_put_str($image, 7, 3, "▙▘▌▙▘▞▖▞▖▌ ▞▖▌ ▌▌");
  63. caca_put_str($image, 7, 4, "▛▖▌▛▖▚▘▚▘▚▖▚▘▚▖▖▖");
  64. caca_set_color_ansi($image, CACA_BLACK, CACA_LIGHTRED);
  65. caca_put_str($image, 4, 3, "▓▒░");
  66. caca_put_str($image, 4, 4, "▓▒░");
  67. caca_put_str($image, 24, 3, "░▒▓");
  68. caca_put_str($image, 24, 4, "░▒▓");
  69. /* Blit the transformed canvas onto the main canvas */
  70. caca_set_color_ansi($cv, CACA_WHITE, CACA_BLUE);
  71. caca_put_str($cv, 0, 0, "normal");
  72. caca_blit($cv, 10, 0, $image);
  73. caca_put_str($cv, 0, 6, "flip");
  74. caca_blit($tmp, 0, 0, $image);
  75. caca_flip($tmp);
  76. caca_blit($cv, 10, 6, $tmp);
  77. caca_put_str($cv, 0, 12, "flop");
  78. caca_blit($tmp, 0, 0, $image);
  79. caca_flop($tmp);
  80. caca_blit($cv, 10, 12, $tmp);
  81. caca_put_str($cv, 0, 18, "rotate");
  82. caca_blit($tmp, 0, 0, $image);
  83. caca_rotate_180($tmp);
  84. caca_blit($cv, 10, 18, $tmp);
  85. caca_refresh_display($dp);
  86. caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1);
  87. ?>