[3111] | 1 | #!/usr/bin/php5 |
---|
[3137] | 2 | <?php |
---|
[3111] | 3 | /* |
---|
| 4 | * demo.php demo for libcaca php binding |
---|
| 5 | * Copyright (c) 2008 Nicolas Vion <nico@yojik.eu> |
---|
| 6 | * |
---|
| 7 | * This file is a Php port of the official libcaca's sample program "demo.c" |
---|
| 8 | * which is: |
---|
| 9 | * Copyright (c) 2003 Sam Hocevar <sam@zoy.org> |
---|
| 10 | * |
---|
| 11 | * This program is free software. It comes without any warranty, to |
---|
| 12 | * the extent permitted by applicable law. You can redistribute it |
---|
| 13 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
| 14 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
| 15 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
| 16 | */ |
---|
| 17 | |
---|
[3177] | 18 | if (php_sapi_name() != "cli") { |
---|
[3175] | 19 | die("You have to run this program with php-cli!\n"); |
---|
[3177] | 20 | } |
---|
[3175] | 21 | |
---|
[3111] | 22 | $string = <<<EOT |
---|
| 23 | |_| |
---|
| 24 | _,----._ | | |
---|
| 25 | (/ @ @ \) __ |
---|
| 26 | | OO | |_ |
---|
| 27 | \ `--' / |__ |
---|
| 28 | `----' |
---|
| 29 | |_| |
---|
| 30 | Hello world! | |
---|
| 31 | EOT; |
---|
| 32 | |
---|
| 33 | $pig = caca_create_canvas(0, 0); |
---|
| 34 | caca_import_string($pig, $string, "text"); |
---|
| 35 | |
---|
| 36 | $cv = caca_create_canvas(caca_get_canvas_width($pig) * 2, caca_get_canvas_height($pig) * 2); |
---|
| 37 | |
---|
| 38 | if (!$cv or !$pig) { |
---|
| 39 | die("Can't created canvas\n"); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | caca_blit($cv, 0, 0, $pig); |
---|
| 43 | caca_flip($pig); |
---|
| 44 | caca_blit($cv, caca_get_canvas_width($pig), 0, $pig); |
---|
| 45 | caca_flip($pig); |
---|
| 46 | caca_flop($pig); |
---|
| 47 | caca_blit($cv, 0, caca_get_canvas_height($pig), $pig); |
---|
| 48 | caca_flop($pig); |
---|
| 49 | caca_rotate_180($pig); |
---|
| 50 | caca_blit($cv, caca_get_canvas_width($pig), caca_get_canvas_height($pig), $pig); |
---|
| 51 | |
---|
| 52 | for($j = 0; $j < caca_get_canvas_height($cv); $j++) { |
---|
| 53 | for($i = 0; $i < caca_get_canvas_width($cv); $i += 2) { |
---|
| 54 | caca_set_color_ansi($cv, CACA_LIGHTBLUE + ($i + $j) % 6, CACA_DEFAULT); |
---|
| 55 | $a = caca_get_attr($cv, -1, -1); |
---|
| 56 | caca_put_attr($cv, $i, $j, $a); |
---|
| 57 | caca_put_attr($cv, $i + 1, $j, $a); |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | echo caca_export_string($cv, "utf8"); |
---|
| 62 | caca_rotate_left($cv); |
---|
| 63 | echo caca_export_string($cv, "utf8"); |
---|
| 64 | |
---|
[3135] | 65 | ?> |
---|