source: libcaca/trunk/caca-php/examples/www/cacainfo.php @ 3183

Last change on this file since 3183 was 3183, checked in by bsittler, 11 years ago

move CSS for www example to a separate file; table is no longer inside <pre>

File size: 2.2 KB
Line 
1<?php
2/*
3 *  cacainfo.php      sample program for libcaca php binding
4 *  Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
5 *
6 *  This program is free software. It comes without any warranty, to
7 *  the extent permitted by applicable law. You can redistribute it
8 *  and/or modify it under the terms of the Do What The Fuck You Want
9 *  To Public License, Version 2, as published by Sam Hocevar. See
10 *  http://sam.zoy.org/wtfpl/COPYING for more details.
11 */
12?>
13<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
14<html>
15<head>
16<title>sample program for libcaca php binding</title>
17<link rel="StyleSheet" href="caca-php.css" >
18</head>
19<body text="white" bgcolor="black">
20<?php
21
22//--- Just for fun ---//
23
24function just_for_fun() {
25
26$moo = <<<EOT
27         (__) 
28         (oo)
29   /------\/
30  / |    ||   
31 *  /\---/\
32    ~~   ~~   
33EOT;
34
35        $cv = caca_create_canvas(0, 0);
36        caca_set_color_ansi($cv, CACA_LIGHTBLUE, CACA_DEFAULT);
37        caca_import_string($cv, $moo, "text");
38
39        for($j = 0; $j < caca_get_canvas_height($cv); $j++) {
40                for($i = 0; $i < caca_get_canvas_width($cv); $i += 2) {
41                        caca_set_color_ansi($cv, (caca_rand(1, 10) > 5 ? CACA_LIGHTBLUE  : CACA_WHITE), CACA_DEFAULT);
42                        $a = caca_get_attr($cv, -1, -1);
43                        caca_put_attr($cv, $i, $j, $a);
44                        caca_put_attr($cv, $i + 1, $j, $a);
45                }
46        }
47        caca_set_color_ansi($cv, CACA_LIGHTGREEN, CACA_DEFAULT);
48        caca_put_str($cv, 8, 0, "Moo!");
49        caca_set_color_ansi($cv, CACA_LIGHTRED, CACA_DEFAULT);
50        caca_put_char($cv, 8, 1, hexdec("2765")); //U+2765
51        caca_put_char($cv, 10, 1, hexdec("2764")); //U+2764
52        echo caca_export_string($cv, "html3");
53}
54       
55
56just_for_fun();
57
58?>
59<pre>
60<?php
61
62//--- Show caca's information ---//
63
64echo "libcaca version: ".caca_get_version()."\n\n";
65echo "Available drivers:\n";
66$list = caca_get_display_driver_list();
67foreach($list as $type => $name)
68        echo "* $name ($type)\n";
69echo "\n";
70
71echo "Available import formats:\n";
72$list = caca_get_import_list();
73foreach($list as $format => $name)
74        echo "* $name ($format)\n";
75echo "\n";
76
77echo "Available export formats:\n";
78$list = caca_get_export_list();
79foreach($list as $format => $name)
80        echo "* $name ($format)\n";
81echo "\n";
82
83echo "Available caca fonts:\n";
84$list = caca_get_font_list();
85foreach($list as $name)
86        echo "* $name\n";
87echo "\n";
88
89?>
90</pre>
91</body>
92</html>
Note: See TracBrowser for help on using the repository browser.