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

Last change on this file since 3251 was 3234, checked in by nico, 12 years ago
  • Remove \t from content of $moo
  • Change canvas size
  • Fix coordinate of label "Moo!"
  • Property svn:executable set to *
File size: 2.1 KB
RevLine 
[3113]1#!/usr/bin/php5
[3126]2<?php
[3172]3/*
4 *  cacainfo.php      sample program for libcaca php binding
5 *  Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
6 *
7 *  This program is free software. It comes without any warranty, to
8 *  the extent permitted by applicable law. You can redistribute it
9 *  and/or modify it under the terms of the Do What The Fuck You Want
10 *  To Public License, Version 2, as published by Sam Hocevar. See
11 *  http://sam.zoy.org/wtfpl/COPYING for more details.
12 */
[3113]13
[3172]14
[3114]15//--- Just for fun ---//
16
17function just_for_fun() {
18
19$moo = <<<EOT
[3234]20         (__)
21         (oo)
[3114]22   /------\/
[3234]23  / |    || 
24 *  /\---/\ 
25    ~~   ~~ 
[3114]26EOT;
27
28        $cv = caca_create_canvas(0, 0);
29        caca_set_color_ansi($cv, CACA_LIGHTBLUE, CACA_DEFAULT);
30        caca_import_string($cv, $moo, "text");
31
32        for($j = 0; $j < caca_get_canvas_height($cv); $j++) {
33                for($i = 0; $i < caca_get_canvas_width($cv); $i += 2) {
34                        caca_set_color_ansi($cv, (caca_rand(1, 10) > 5 ? CACA_LIGHTBLUE  : CACA_WHITE), CACA_DEFAULT);
35                        $a = caca_get_attr($cv, -1, -1);
36                        caca_put_attr($cv, $i, $j, $a);
37                        caca_put_attr($cv, $i + 1, $j, $a);
38                }
39        }
[3234]40        caca_set_canvas_size($cv, 18, 6);
[3114]41        caca_set_color_ansi($cv, CACA_LIGHTGREEN, CACA_DEFAULT);
[3234]42        caca_put_str($cv, 14, 0, "Moo!");
[3132]43        caca_set_color_ansi($cv, CACA_LIGHTRED, CACA_DEFAULT);
[3234]44        caca_put_char($cv, 14, 1, hexdec("2765")); //U+2765
45        caca_put_char($cv, 16, 1, hexdec("2764")); //U+2764
[3114]46        echo caca_export_string($cv, "utf8");
47}
48       
49
[3177]50if (php_sapi_name() != "cli") {
[3175]51        die("You have to run this program with php-cli!\n");
[3177]52}
[3175]53
[3114]54just_for_fun();
55
56//--- Show caca's information ---//
57
58echo "libcaca version: ".caca_get_version()."\n\n";
[3113]59echo "Available drivers:\n";
60$list = caca_get_display_driver_list();
61foreach($list as $type => $name)
62        echo "* $name ($type)\n";
[3114]63echo "\n";
64
[3126]65echo "Available import formats:\n";
66$list = caca_get_import_list();
67foreach($list as $format => $name)
68        echo "* $name ($format)\n";
69echo "\n";
70
71echo "Available export formats:\n";
[3114]72$list = caca_get_export_list();
[3126]73foreach($list as $format => $name)
74        echo "* $name ($format)\n";
[3114]75echo "\n";
76
77echo "Available caca fonts:\n";
78$list = caca_get_font_list();
79foreach($list as $name)
80        echo "* $name\n";
81echo "\n";
[3135]82
83?>
Note: See TracBrowser for help on using the repository browser.