1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
---|
3 | |
---|
4 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
---|
5 | <?php |
---|
6 | /* |
---|
7 | * demo.php demo for libcaca php binding |
---|
8 | * Copyright (c) 2008 Nicolas Vion <nico@yojik.eu> |
---|
9 | * |
---|
10 | * This file is a Php port of the official libcaca's sample program "demo.c" |
---|
11 | * which is: |
---|
12 | * Copyright (c) 2003 Sam Hocevar <sam@zoy.org> |
---|
13 | * |
---|
14 | * This program is free software. It comes without any warranty, to |
---|
15 | * the extent permitted by applicable law. You can redistribute it |
---|
16 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
17 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
18 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
19 | */ |
---|
20 | ?> |
---|
21 | <head> |
---|
22 | <title>demo for libcaca php binding</title> |
---|
23 | <link rel="StyleSheet" href="caca-php.css" type="text/css" /> |
---|
24 | </head> |
---|
25 | <body text="silver" bgcolor="black"> |
---|
26 | <?php |
---|
27 | |
---|
28 | $string = <<<EOT |
---|
29 | |_| |
---|
30 | _,----._ | | |
---|
31 | (/ @ @ \) __ |
---|
32 | | OO | |_ |
---|
33 | \ `--' / |__ |
---|
34 | `----' |
---|
35 | |_| |
---|
36 | Hello world! | |
---|
37 | EOT; |
---|
38 | |
---|
39 | $pig = caca_create_canvas(0, 0); |
---|
40 | caca_import_string($pig, $string, "text"); |
---|
41 | |
---|
42 | $cv = caca_create_canvas(caca_get_canvas_width($pig) * 2, caca_get_canvas_height($pig) * 2); |
---|
43 | |
---|
44 | if (!$cv or !$pig) { |
---|
45 | die("Can't created canvas\n"); |
---|
46 | } |
---|
47 | |
---|
48 | caca_blit($cv, 0, 0, $pig); |
---|
49 | caca_flip($pig); |
---|
50 | caca_blit($cv, caca_get_canvas_width($pig), 0, $pig); |
---|
51 | caca_flip($pig); |
---|
52 | caca_flop($pig); |
---|
53 | caca_blit($cv, 0, caca_get_canvas_height($pig), $pig); |
---|
54 | caca_flop($pig); |
---|
55 | caca_rotate_180($pig); |
---|
56 | caca_blit($cv, caca_get_canvas_width($pig), caca_get_canvas_height($pig), $pig); |
---|
57 | |
---|
58 | for($j = 0; $j < caca_get_canvas_height($cv); $j++) { |
---|
59 | for($i = 0; $i < caca_get_canvas_width($cv); $i += 2) { |
---|
60 | caca_set_color_ansi($cv, CACA_LIGHTBLUE + ($i + $j) % 6, CACA_DEFAULT); |
---|
61 | $a = caca_get_attr($cv, -1, -1); |
---|
62 | caca_put_attr($cv, $i, $j, $a); |
---|
63 | caca_put_attr($cv, $i + 1, $j, $a); |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | echo caca_export_string($cv, "html3"); |
---|
68 | caca_rotate_left($cv); |
---|
69 | echo caca_export_string($cv, "html3"); |
---|
70 | |
---|
71 | ?> |
---|
72 | </body> |
---|
73 | </html> |
---|