1 | <html> |
---|
2 | <head> |
---|
3 | <title>sample program for libcaca php binding</title> |
---|
4 | </head> |
---|
5 | <body text="white" bgcolor="blue"> |
---|
6 | <pre> |
---|
7 | <?php |
---|
8 | /* |
---|
9 | * cacainfo.php sample program for libcaca php binding |
---|
10 | * Copyright (c) 2008 Nicolas Vion <nico@yojik.eu> |
---|
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 | |
---|
19 | |
---|
20 | //--- Just for fun ---// |
---|
21 | |
---|
22 | function just_for_fun() { |
---|
23 | |
---|
24 | $moo = <<<EOT |
---|
25 | (__) |
---|
26 | (oo) |
---|
27 | /------\/ |
---|
28 | / | || |
---|
29 | * /\---/\ |
---|
30 | ~~ ~~ |
---|
31 | EOT; |
---|
32 | |
---|
33 | $cv = caca_create_canvas(0, 0); |
---|
34 | caca_set_color_ansi($cv, CACA_LIGHTBLUE, CACA_DEFAULT); |
---|
35 | caca_import_string($cv, $moo, "text"); |
---|
36 | |
---|
37 | for($j = 0; $j < caca_get_canvas_height($cv); $j++) { |
---|
38 | for($i = 0; $i < caca_get_canvas_width($cv); $i += 2) { |
---|
39 | caca_set_color_ansi($cv, (caca_rand(1, 10) > 5 ? CACA_LIGHTBLUE : CACA_WHITE), CACA_DEFAULT); |
---|
40 | $a = caca_get_attr($cv, -1, -1); |
---|
41 | caca_put_attr($cv, $i, $j, $a); |
---|
42 | caca_put_attr($cv, $i + 1, $j, $a); |
---|
43 | } |
---|
44 | } |
---|
45 | caca_set_color_ansi($cv, CACA_LIGHTGREEN, CACA_DEFAULT); |
---|
46 | caca_put_str($cv, 8, 0, "Moo!"); |
---|
47 | caca_set_color_ansi($cv, CACA_LIGHTRED, CACA_DEFAULT); |
---|
48 | caca_put_char($cv, 8, 1, hexdec("2765")); //U+2765 |
---|
49 | caca_put_char($cv, 10, 1, hexdec("2764")); //U+2764 |
---|
50 | echo caca_export_string($cv, "html3"); |
---|
51 | } |
---|
52 | |
---|
53 | |
---|
54 | just_for_fun(); |
---|
55 | |
---|
56 | //--- Show caca's information ---// |
---|
57 | |
---|
58 | echo "libcaca version: ".caca_get_version()."\n\n"; |
---|
59 | echo "Available drivers:\n"; |
---|
60 | $list = caca_get_display_driver_list(); |
---|
61 | foreach($list as $type => $name) |
---|
62 | echo "* $name ($type)\n"; |
---|
63 | echo "\n"; |
---|
64 | |
---|
65 | echo "Available import formats:\n"; |
---|
66 | $list = caca_get_import_list(); |
---|
67 | foreach($list as $format => $name) |
---|
68 | echo "* $name ($format)\n"; |
---|
69 | echo "\n"; |
---|
70 | |
---|
71 | echo "Available export formats:\n"; |
---|
72 | $list = caca_get_export_list(); |
---|
73 | foreach($list as $format => $name) |
---|
74 | echo "* $name ($format)\n"; |
---|
75 | echo "\n"; |
---|
76 | |
---|
77 | echo "Available caca fonts:\n"; |
---|
78 | $list = caca_get_font_list(); |
---|
79 | foreach($list as $name) |
---|
80 | echo "* $name\n"; |
---|
81 | echo "\n"; |
---|
82 | |
---|
83 | ?> |
---|
84 | </pre> |
---|
85 | </body> |
---|
86 | </html> |
---|