source: libcaca/trunk/caca-php/examples/text.php @ 3175

Last change on this file since 3175 was 3175, checked in by nico, 12 years ago
  • Check that samples programs are executed with php-cli
  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#!/usr/bin/php5
2<?php
3/*
4 *  demo.php      demo for libcaca php binding
5 *  Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
6 *
7 *  This file is a Php port of the official libcaca's sample program "demo.c"
8 *  which is:
9 *  Copyright (c) 2003 Sam Hocevar <sam@zoy.org>
10 *
11 *  This program is free software. It comes without any warranty, to
12 *  the extent permitted by applicable law. You can redistribute it
13 *  and/or modify it under the terms of the Do What The Fuck You Want
14 *  To Public License, Version 2, as published by Sam Hocevar. See
15 *  http://sam.zoy.org/wtfpl/COPYING for more details.
16 */
17
18if (!posix_isatty(STDOUT))
19        die("You have to run this program with php-cli!\n");
20
21$string =  <<<EOT
22              |_|
23   _,----._   | |
24  (/ @  @ \)   __
25   |  OO  |   |_ 
26   \ `--' /   |__
27    `----'       
28              |_|
29 Hello world!  | 
30EOT;
31       
32$pig = caca_create_canvas(0, 0);
33caca_import_string($pig, $string, "text");
34
35$cv = caca_create_canvas(caca_get_canvas_width($pig) * 2, caca_get_canvas_height($pig) * 2);
36
37if (!$cv or !$pig) {
38        die("Can't created canvas\n");
39}
40
41caca_blit($cv, 0, 0, $pig);
42caca_flip($pig);
43caca_blit($cv, caca_get_canvas_width($pig), 0, $pig);
44caca_flip($pig);
45caca_flop($pig);
46caca_blit($cv, 0, caca_get_canvas_height($pig), $pig);
47caca_flop($pig);
48caca_rotate_180($pig);
49caca_blit($cv, caca_get_canvas_width($pig), caca_get_canvas_height($pig), $pig);
50
51for($j = 0; $j < caca_get_canvas_height($cv); $j++) {
52        for($i = 0; $i < caca_get_canvas_width($cv); $i += 2) {
53                caca_set_color_ansi($cv, CACA_LIGHTBLUE + ($i + $j) % 6, CACA_DEFAULT);
54                $a = caca_get_attr($cv, -1, -1);
55                caca_put_attr($cv, $i, $j, $a);
56                caca_put_attr($cv, $i + 1, $j, $a);
57        }
58}
59
60echo caca_export_string($cv, "utf8");
61caca_rotate_left($cv);
62echo caca_export_string($cv, "utf8");
63
64?>
Note: See TracBrowser for help on using the repository browser.