Debian Codegraph @

caca-php/examples/www/cacainfo.php

raw
1 <?php
2 header('Content-Type: text/html; charset=UTF-8');
3 ?>
4 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
7 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
8 <?php
9 /*
10 * cacainfo.php sample program for libcaca php binding
11 * Copyright (c) 2008 Nicolas Vion <[email protected]>
12 *
13 * This program is free software. It comes without any warranty, to
14 * the extent permitted by applicable law. You can redistribute it
15 * and/or modify it under the terms of the Do What the Fuck You Want
16 * to Public License, Version 2, as published by Sam Hocevar. See
17 * http://www.wtfpl.net/ for more details.
18 */
19 ?>
20 <head>
21 <title>sample program for libcaca php binding</title>
22 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
23 </head>
24 <body text="silver" bgcolor="black">
25 <?php
26
27 //--- Just for fun ---//
28
29 function just_for_fun() {
30
31 $moo = <<<EOT
32 (__)
33 (oo)
34 /------\/
35 / | ||
36 * /\---/\
37 ~~ ~~
38 EOT;
39
40 $cv = caca_create_canvas(0, 0);
41 caca_set_color_ansi($cv, CACA_LIGHTBLUE, CACA_DEFAULT);
42 caca_import_string($cv, $moo, "text");
43
44 for($j = 0; $j < caca_get_canvas_height($cv); $j++) {
45 for($i = 0; $i < caca_get_canvas_width($cv); $i += 2) {
46 caca_set_color_ansi($cv, (caca_rand(1, 10) > 5 ? CACA_LIGHTBLUE : CACA_WHITE), CACA_DEFAULT);
47 $a = caca_get_attr($cv, -1, -1);
48 caca_put_attr($cv, $i, $j, $a);
49 caca_put_attr($cv, $i + 1, $j, $a);
50 }
51 }
52 caca_set_canvas_size($cv, 18, 6);
53 caca_set_color_ansi($cv, CACA_LIGHTGREEN, CACA_DEFAULT);
54 caca_put_str($cv, 14, 0, "Moo!");
55 caca_set_color_ansi($cv, CACA_LIGHTRED, CACA_DEFAULT);
56 caca_put_char($cv, 14, 1, hexdec("2765")); //U+2765
57 caca_put_char($cv, 16, 1, hexdec("2764")); //U+2764
58 echo caca_export_string($cv, "html3");
59 }
60
61
62 just_for_fun();
63
64 ?>
65 <?php
66
67 //--- Show caca's information ---//
68
69 ?>
70 <p>libcaca version: <?php echo htmlspecialchars(caca_get_version()); ?></p>
71
72 <p>Available drivers:</p>
73 <ul>
74 <?php
75 $list = caca_get_display_driver_list();
76 foreach($list as $type => $name)
77 echo '<li>' . htmlspecialchars("$name ($type)") . '</li>';
78 ?>
79 </ul>
80
81 <p>Available import formats:</p>
82 <ul>
83 <?php
84 $list = caca_get_import_list();
85 foreach($list as $format => $name)
86 echo '<li>' . htmlspecialchars("$name ($format)") . '</li>';
87 ?>
88 </ul>
89
90 <p>Available export formats:</p>
91 <ul>
92 <?php
93 $list = caca_get_export_list();
94 foreach($list as $format => $name)
95 echo '<li>' . htmlspecialchars("$name ($format)") . '</li>';
96 ?>
97 </ul>
98
99 <p>Available caca fonts:</p>
100 <ul>
101 <?php
102 $list = caca_get_font_list();
103 foreach($list as $name)
104 echo '<li>' . htmlspecialchars("$name") . '</li>';
105 ?>
106 </ul>
107
108 </body>
109 </html>