Example #1
0
function just_for_fun()
{
    $moo = <<<EOT
         (__)
         (oo)
   /------\\/
  / |    ||
 *  /\\---/\\
    ~~   ~~
EOT;
    $cv = caca_create_canvas(0, 0);
    caca_set_color_ansi($cv, CACA_LIGHTBLUE, CACA_DEFAULT);
    caca_import_string($cv, $moo, "text");
    for ($j = 0; $j < caca_get_canvas_height($cv); $j++) {
        for ($i = 0; $i < caca_get_canvas_width($cv); $i += 2) {
            caca_set_color_ansi($cv, caca_rand(1, 10) > 5 ? CACA_LIGHTBLUE : CACA_WHITE, CACA_DEFAULT);
            $a = caca_get_attr($cv, -1, -1);
            caca_put_attr($cv, $i, $j, $a);
            caca_put_attr($cv, $i + 1, $j, $a);
        }
    }
    caca_set_canvas_size($cv, 18, 6);
    caca_set_color_ansi($cv, CACA_LIGHTGREEN, CACA_DEFAULT);
    caca_put_str($cv, 14, 0, "Moo!");
    caca_set_color_ansi($cv, CACA_LIGHTRED, CACA_DEFAULT);
    caca_put_char($cv, 14, 1, hexdec("2765"));
    //U+2765
    caca_put_char($cv, 16, 1, hexdec("2764"));
    //U+2764
    echo caca_export_string($cv, "html3");
}
Example #2
0
</head>
<body>
<?php 
/*
 *  dithering.php      sample program for libcaca php binding
 *  Copyright (c) 2008 Nicolas Vion <*****@*****.**>
 *
 *  This program is free software. It comes without any warranty, to
 *  the extent permitted by applicable law. You can redistribute it
 *  and/or modify it under the terms of the Do What the F**k You Want
 *  to Public License, Version 2, as published by Sam Hocevar. See
 *  http://www.wtfpl.net/ for more details.
 */
$src = "logo-caca.png";
$img = imagecreatefrompng(dirname(__FILE__) . "/" . $src);
if (!$img) {
    die("Can not open image.\n");
}
$dither = caca_create_dither($img);
if (!$dither) {
    die("Can not create dither. Maybe you compiled caca-php without gd support.\n");
}
$canvas = caca_create_canvas(100, 40);
caca_dither_bitmap($canvas, 0, 0, caca_get_canvas_width($canvas), caca_get_canvas_height($canvas), $dither, $img);
echo caca_export_string($canvas, "html3");
echo "<img src=\"./{$src}\" alt=\"\" />";
?>
</body>
</html>

Example #3
0
File: caca.php Project: dns/libcaca
 function getHeight()
 {
     return caca_get_canvas_height($this->cv);
 }
Example #4
0
           | |  |  ``/  /`  /
      jgs /,_|  |   /,_/   /
             /,_/      '`-'
EOT;
    $canvas = caca_create_canvas(0, 0);
    caca_set_color_ansi($canvas, CACA_RED, CACA_WHITE);
    caca_import_string($canvas, $pig_str, "text");
    caca_set_color_ansi($canvas, CACA_BLUE, CACA_LIGHTGRAY);
    caca_put_str($canvas, 0, 0, "Я люблю Либкаку");
    return $canvas;
}
if (isset($_GET["png"])) {
    $canvas = pig();
    $font = caca_load_builtin_font("Monospace Bold 12");
    $width = caca_get_canvas_width($canvas) * caca_get_font_width($font);
    $height = caca_get_canvas_height($canvas) * caca_get_font_height($font);
    $img = imagecreatetruecolor($width, $height);
    caca_render_canvas($canvas, $font, $img);
    header("Content-type: image/png");
    imagepng($img);
} else {
    $render_php = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : 'render.php';
    header("Content-type: text/html; charset=UTF-8");
    ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Я люблю Либкаку</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Example #5
0
    }
} else {
    $cv = caca_create_canvas(WIDTH, HEIGHT);
    for ($y = 0; $y < 256; $y++) {
        for ($x = 0; $x < 256; $x++) {
            $r = $x;
            $g = (255 - $y + $x) / 2;
            $b = $y * (255 - $x) / 256;
            imagesetpixel($pixels, $x, $y, imagecolorallocate($pixels, $r, $g, $b));
        }
    }
    $dither = caca_create_dither($pixels);
    if ($format == "ansi" || $format == "utf8") {
        caca_set_dither_charset($dither, "shades");
    }
    caca_dither_bitmap($cv, 0, 0, caca_get_canvas_width($cv), caca_get_canvas_height($cv), $dither, $pixels);
    caca_set_color_ansi($cv, CACA_WHITE, CACA_BLACK);
    caca_draw_thin_box($cv, 0, 0, WIDTH - 1, HEIGHT - 1);
    caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
    caca_fill_ellipse($cv, WIDTH / 2, HEIGHT / 2, WIDTH / 4, HEIGHT / 4, ord(' '));
    caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
    caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 6, "   lightgray on black   ");
    caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT);
    caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 5, " default on transparent ");
    caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
    caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 4, "     black on white     ");
    caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
    caca_put_str($cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]");
    caca_put_str($cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]");
    caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
    caca_put_str($cv, WIDTH / 2 - 5, HEIGHT / 2 + 4, "(\") \\o/ <&>");
Example #6
0
File: text.php Project: dns/libcaca
   \\ `--' /   |__
    `----'
              |_|
 Hello world!  |
EOT;
$pig = caca_create_canvas(0, 0);
caca_import_string($pig, $string, "text");
$cv = caca_create_canvas(caca_get_canvas_width($pig) * 2, caca_get_canvas_height($pig) * 2);
if (!$cv or !$pig) {
    die("Can't created canvas\n");
}
caca_blit($cv, 0, 0, $pig);
caca_flip($pig);
caca_blit($cv, caca_get_canvas_width($pig), 0, $pig);
caca_flip($pig);
caca_flop($pig);
caca_blit($cv, 0, caca_get_canvas_height($pig), $pig);
caca_flop($pig);
caca_rotate_180($pig);
caca_blit($cv, caca_get_canvas_width($pig), caca_get_canvas_height($pig), $pig);
for ($j = 0; $j < caca_get_canvas_height($cv); $j++) {
    for ($i = 0; $i < caca_get_canvas_width($cv); $i += 2) {
        caca_set_color_ansi($cv, CACA_LIGHTBLUE + ($i + $j) % 6, CACA_DEFAULT);
        $a = caca_get_attr($cv, -1, -1);
        caca_put_attr($cv, $i, $j, $a);
        caca_put_attr($cv, $i + 1, $j, $a);
    }
}
echo caca_export_string($cv, "utf8");
caca_rotate_left($cv);
echo caca_export_string($cv, "utf8");
Example #7
0
File: demo.php Project: dns/libcaca
function demo_triangles($cv, $bounds, $outline)
{
    $w = caca_get_canvas_width($cv);
    $h = caca_get_canvas_height($cv);
    if ($bounds) {
        $xa = caca_rand(-$w, 2 * $w);
        $ya = caca_rand(-$h, 2 * $h);
        $xb = caca_rand(-$w, 2 * $w);
        $yb = caca_rand(-$h, 2 * $h);
        $xc = caca_rand(-$w, 2 * $w);
        $yc = caca_rand(-$h, 2 * $h);
    } else {
        $xa = caca_rand(0, $w);
        $ya = caca_rand(0, $h);
        $xb = caca_rand(0, $w);
        $yb = caca_rand(0, $h);
        $xc = caca_rand(0, $w);
        $yc = caca_rand(0, $h);
    }
    caca_set_color_ansi($cv, caca_rand(0, 16), caca_rand(0, 16));
    caca_fill_triangle($cv, $xa, $ya, $xb, $yb, $xc, $yc, ord('#'));
    caca_set_color_ansi($cv, caca_rand(0, 16), CACA_BLACK);
    if ($outline == 2) {
        caca_draw_thin_triangle($cv, $xa, $ya, $xb, $yb, $xc, $yc);
    } else {
        if ($outline == 1) {
            caca_draw_triangle($cv, $xa, $ya, $xb, $yb, $xc, $yc, ord('#'));
        }
    }
}