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

Last change on this file since 3185 was 3185, checked in by bsittler, 13 years ago

now HTML markup is generated, rather than a giant PRE block

File size: 2.4 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="silver" 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<?php
60
61//--- Show caca's information ---//
62
63?>
64<p>libcaca version: <?php echo htmlspecialchars(caca_get_version()); ?></p>
65
66<p>Available drivers:</p>
67<ul>
68<?php
69$list = caca_get_display_driver_list();
70foreach($list as $type => $name)
71        echo '<li>' . htmlspecialchars("$name ($type)") . '</li>';
72?>
73</ul>
74
75<p>Available import formats:</p>
76<ul>
77<?php
78$list = caca_get_import_list();
79foreach($list as $format => $name)
80        echo '<li>' . htmlspecialchars("$name ($format)") . '</li>';
81?>
82</ul>
83
84<p>Available export formats:<p>
85<ul>
86<?php
87$list = caca_get_export_list();
88foreach($list as $format => $name)
89        echo '<li>' . htmlspecialchars("$name ($format)") . '</li>';
90?>
91</ul>
92
93<p>Available caca fonts:</p>
94<ul>
95<?php
96$list = caca_get_font_list();
97foreach($list as $name)
98        echo '<li>' . htmlspecialchars("$name") . '</li>';
99?>
100</ul>
101
102</body>
103</html>
Note: See TracBrowser for help on using the repository browser.