Beispiel #1
0
function pig()
{
    $pig_str = <<<EOT

    _._ _..._ .-',     _.._(`))
   '-. `     '  /-._.-'    ',/
      )         \\            '.
     / _    _    |             \\
    |  a    a    /   PHP        |
    \\   .-.                     ;
     '-('' ).-'       ,'       ;
        '-;           |      .'
           \\           \\    /
           | 7  .__  _.-\\   \\
           | |  |  ``/  /`  /
      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;
}
Beispiel #2
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");
}
Beispiel #3
0
caca_put_str($cv, 1, 9, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
caca_put_str($cv, 1, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
caca_put_str($cv, 1, 11, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
caca_put_str($cv, 1, 12, "█████████████████████████████");
caca_set_color_ansi($cv, CACA_LIGHTGREEN, CACA_LIGHTRED);
caca_put_str($cv, 36, 8, "█████████████████████████████");
caca_put_str($cv, 36, 9, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
caca_put_str($cv, 36, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
caca_put_str($cv, 36, 11, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
caca_put_str($cv, 36, 12, "                             ");
caca_set_color_ansi($cv, CACA_WHITE, CACA_BLUE);
caca_put_str($cv, 1, 14, "Double width characters");
caca_set_color_ansi($cv, CACA_LIGHTRED, CACA_TRANSPARENT);
caca_put_str($cv, 1, 15, "| ドラゴン ボーレ |");
caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT);
caca_put_str($cv, 1, 16, "| ()()()() ()()() |");
caca_set_color_ansi($cv, CACA_YELLOW, CACA_TRANSPARENT);
caca_put_str($cv, 1, 17, "| ドラゴン");
caca_put_str($cv, 12, 17, "ボーレ |");
caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT);
caca_put_str($cv, 1, 18, "If the three lines do not have the same length, there is a bug somewhere.");
caca_put_str($cv, 1, 20, "CP437 glyphs: ☺ ☻ ♥ ♦ ♣ ♠ • ◘ ○ ◙ ♂ ♀ ♪ ♫ ☼ ► ◄ ↕ ‼ ¶ § ▬ ↨ ↑ ↓ → ← ∟ ↔ ▲ ▼");
caca_put_str($cv, 1, 21, "more CP437: α ß Γ π Σ σ µ τ Φ Θ Ω δ ∞ φ ε ∩ ≡ ± ≥ ≤ ⌠ ⌡ ÷ ≈ ° ∙ · √ ⁿ ² ■");
caca_put_str($cv, 1, 22, "drawing blocks: ███ ▓▓▓ ▒▒▒ ░░░ ▀ ▄ ▌ ▐ █ ▖ ▗ ▘ ▝ ▚ ▞ ▙ ▛ ▜ ▟ ─ │ ┌ ┐ └ ┘ ├ ┤");
caca_put_str($cv, 1, 23, "more drawing: ┬ ┴ ┼ ═ ║ ╒ ╓ ╔ ╕ ╖ ╗ ╘ ╙ ╚ ╛ ╜ ╝ ╞ ╟ ╠ ╡ ╢ ╣ ╤ ╥ ╦ ╧ ╨ ╩ ╪ ╫ ╬");
caca_put_str($cv, 1, 24, "misc Unicode: ● ☭ ☮ ☯ ♔ ♛ ♙ ♞ ⚒ ⚓ ⚠");
echo caca_export_string($cv, "html3");
?>
</body>
</html>
Beispiel #4
0
 function putStr($x, $y, $str)
 {
     return caca_put_str($this->cv, $x, $y, $str);
 }
Beispiel #5
0
 *  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.
 */
function transform($tbl, $tx, $ty, $sx, $sy)
{
    $result = array();
    foreach ($tbl as $pt) {
        $result[] = array($pt[0] * $sx + $tx, $pt[1] * $sy + $ty);
    }
    return $result;
}
if (php_sapi_name() != "cli") {
    die("You have to run this program with php-cli!\n");
}
$canvas = caca_create_canvas(0, 0);
$display = caca_create_display($canvas);
if (!$display) {
    die("Error while attaching canvas to display\n");
}
$tbl = array(array(5, 2), array(15, 2), array(20, 4), array(25, 2), array(34, 2), array(37, 4), array(36, 9), array(20, 16), array(3, 9), array(2, 4), array(5, 2));
for ($i = 0; $i < 10; $i++) {
    caca_set_color_ansi($canvas, 1 + ($color += 4) % 15, CACA_TRANSPARENT);
    $scale = caca_rand(4, 10) / 10;
    $translate = array(caca_rand(-5, 55), caca_rand(-2, 25));
    $pts = transform($tbl, $translate[0], $translate[1], $scale, $scale);
    caca_draw_thin_polyline($canvas, $pts);
}
caca_put_str($canvas, 1, 1, "Caca forever...");
caca_refresh_display($display);
caca_get_event($display, CACA_EVENT_KEY_PRESS, 5000000);
Beispiel #6
0
<body text="silver" bgcolor="black">
<?php 
$cv = caca_create_canvas(80, 24);
if (!$cv) {
    die("Failed to create canvas\n");
}
caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
caca_clear_canvas($cv);
for ($i = 0; $i < 16; $i++) {
    caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
    caca_put_str($cv, 3, $i + ($i >= 8 ? 3 : 2), "ANSI " . $i);
    for ($j = 0; $j < 16; $j++) {
        caca_set_color_ansi($cv, $i, $j);
        caca_put_str($cv, ($j >= 8 ? 13 : 12) + $j * 4, $i + ($i >= 8 ? 3 : 2), "Aaホ");
    }
}
caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
caca_put_str($cv, 3, 20, "This is bold    This is blink    This is italics    This is underline");
caca_set_attr($cv, CACA_BOLD);
caca_put_str($cv, 3 + 8, 20, "bold");
caca_set_attr($cv, CACA_BLINK);
caca_put_str($cv, 3 + 24, 20, "blink");
caca_set_attr($cv, CACA_ITALICS);
caca_put_str($cv, 3 + 41, 20, "italics");
caca_set_attr($cv, CACA_UNDERLINE);
caca_put_str($cv, 3 + 60, 20, "underline");
echo caca_export_string($cv, "html3");
?>
</body>
</html>
Beispiel #7
0
    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/ <&>");
    caca_set_attr($cv, CACA_BOLD);
    caca_put_str($cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold");
    caca_set_attr($cv, CACA_BLINK);
    caca_put_str($cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink");
    caca_set_attr($cv, CACA_ITALICS);
    caca_put_str($cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics");
    caca_set_attr($cv, CACA_UNDERLINE);
    caca_put_str($cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline");
    caca_set_attr($cv, 0);
    caca_set_color_ansi($cv, CACA_WHITE, CACA_LIGHTBLUE);
    caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2, "    LIBCACA    ");
    for ($x = 0; $x < 16; $x++) {
        caca_set_color_argb($cv, 0xff00 | $x, 0xf00f | $x << 4);
        caca_put_char($cv, WIDTH / 2 - 7 + $x, HEIGHT / 2 + 6, ord('#'));
    }
}
$content_type_map = array('ansi' => 'text/plain; charset=CP437', 'utf8' => 'text/plain; charset=UTF-8', 'utf8cr' => 'text/plain; charset=UTF-8', 'html' => 'text/html; charset=UTF-8', 'html3' => 'text/html; charset=UTF-8', 'bbfr' => 'text/plain; charset=UTF-8', 'irc' => 'text/plain; charset=UTF-8', 'ps' => 'application/postscript', 'svg' => 'image/svg+xml', 'tga' => 'image/x-targa');
$download_extension_map = array('caca' => 'caca', 'ansi' => 'txt', 'utf8' => 'txt', 'utf8cr' => 'txt', 'irc' => 'txt', 'tga' => 'tga');
$inline_extension_map = array('bbfr' => 'txt', 'ps' => 'ps', 'svg' => 'svg');
if (!array_key_exists($format, $content_type_map)) {
    $content_type = 'application/octet-stream';
} else {
    $content_type = $content_type_map[$format];
}
header('Content-Type: ' . $content_type);
if (array_key_exists($format, $download_extension_map)) {
Beispiel #8
0
caca_put_str($image, 1, 1, "hahaha mais vieux porc immonde !! [⽼ ⾗]");
caca_set_color_ansi($image, CACA_LIGHTRED, CACA_BLACK);
caca_put_char($image, 38, 1, ord('|'));
caca_set_color_ansi($image, CACA_YELLOW, CACA_BLACK);
caca_put_str($image, 4, 2, "\\o\\ \\o| _o/ \\o_ |o/ /o/");
caca_set_color_ansi($image, CACA_WHITE, CACA_LIGHTRED);
caca_put_str($image, 7, 3, "▙▘▌▙▘▞▖▞▖▌ ▞▖▌ ▌▌");
caca_put_str($image, 7, 4, "▛▖▌▛▖▚▘▚▘▚▖▚▘▚▖▖▖");
caca_set_color_ansi($image, CACA_BLACK, CACA_LIGHTRED);
caca_put_str($image, 4, 3, "▓▒░");
caca_put_str($image, 4, 4, "▓▒░");
caca_put_str($image, 24, 3, "░▒▓");
caca_put_str($image, 24, 4, "░▒▓");
/* Blit the transformed canvas onto the main canvas */
caca_set_color_ansi($cv, CACA_WHITE, CACA_BLUE);
caca_put_str($cv, 0, 0, "normal");
caca_blit($cv, 10, 0, $image);
caca_put_str($cv, 0, 6, "flip");
caca_blit($tmp, 0, 0, $image);
caca_flip($tmp);
caca_blit($cv, 10, 6, $tmp);
caca_put_str($cv, 0, 12, "flop");
caca_blit($tmp, 0, 0, $image);
caca_flop($tmp);
caca_blit($cv, 10, 12, $tmp);
caca_put_str($cv, 0, 18, "rotate");
caca_blit($tmp, 0, 0, $image);
caca_rotate_180($tmp);
caca_blit($cv, 10, 18, $tmp);
caca_refresh_display($dp);
caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1);
Beispiel #9
0
 *          All Rights Reserved
 *
 *  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.
 */
if (php_sapi_name() != "cli") {
    die("You have to run this program with php-cli!\n");
}
$cv = caca_create_canvas(32, 16);
if (!$cv) {
    die("Failed to create canvas\n");
}
$dp = caca_create_display($cv);
if (!$dp) {
    die("Failed to create display\n");
}
for ($y = 0; $y < 16; $y++) {
    for ($x = 0; $x < 16; $x++) {
        $bgcolor = 0xff00 | $y << 4 | $x;
        $fgcolor = 0xf000 | 15 - $y << 4 | 15 - $x << 8;
        caca_set_color_argb($cv, $fgcolor, $bgcolor);
        caca_put_str($cv, $x * 2, $y, "CA");
    }
}
caca_set_color_ansi($cv, CACA_WHITE, CACA_LIGHTBLUE);
caca_put_str($cv, 2, 1, " truecolor libcaca ");
caca_refresh_display($dp);
caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1);
Beispiel #10
0
    die("Can't create display\n");
}
$caca = caca_create_canvas(6, 10);
$line = caca_create_canvas(2, 1);
/* Line of x's */
for ($i = 0; $i < 10; $i++) {
    caca_set_color_ansi($caca, CACA_WHITE, CACA_BLUE);
    caca_put_str($caca, 0, $i, CACA);
    caca_set_color_ansi($caca, CACA_WHITE, CACA_RED);
    caca_put_char($caca, $i - 2, $i, ord('x'));
}
caca_blit($cv, 1, 1, $caca);
/* Line of ホ's */
for ($i = 0; $i < 10; $i++) {
    caca_set_color_ansi($caca, CACA_WHITE, CACA_BLUE);
    caca_put_str($caca, 0, $i, CACA);
    caca_set_color_ansi($caca, CACA_WHITE, CACA_GREEN);
    caca_put_str($caca, $i - 2, $i, "ホ");
}
caca_blit($cv, 15, 1, $caca);
/* Line of canvas */
caca_set_color_ansi($line, CACA_WHITE, CACA_MAGENTA);
caca_put_str($line, 0, 0, "ほ");
for ($i = 0; $i < 10; $i++) {
    caca_set_color_ansi($caca, CACA_WHITE, CACA_BLUE);
    caca_put_str($caca, 0, $i, CACA);
    caca_blit($caca, $i - 2, $i, $line);
}
caca_blit($cv, 29, 1, $caca);
caca_refresh_display($dp);
caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1);
Beispiel #11
0
    die("You have to run this program with php-cli!\n");
}
$pig_str = <<<EOT

    _._ _..._ .-',     _.._(`))
   '-. `     '  /-._.-'    ',/
      )         \\            '.
     / _    _    |             \\
    |  a    a    /   PHP        |
    \\   .-.                     ;
     '-('' ).-'       ,'       ;
        '-;           |      .'
           \\           \\    /
           | 7  .__  _.-\\   \\
           | |  |  ``/  /`  /
      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, "Я люблю Либкаку");
echo caca_export_string($canvas, "utf8");
$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);
imagepng($img, "out.png");
echo "Please, open new created png file: out.png\n";
Beispiel #12
0
function demo_go($dp, $demo, $cv, $bounds, $outline)
{
    caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
    caca_clear_canvas($cv);
    while (!caca_get_event($dp, CACA_EVENT_KEY_PRESS)) {
        if (function_exists($demo)) {
            $demo($cv, $bounds, $outline);
        }
        caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
        caca_draw_thin_box($cv, 1, 1, caca_get_canvas_width($cv) - 2, caca_get_canvas_height($cv) - 2);
        $rate = sprintf("%01.2f", 1000000 / caca_get_display_time($dp));
        caca_put_str($cv, 4, 1, "[{$rate} fps]----");
        caca_refresh_display($dp);
    }
    display_menu($cv, $dp, $bounds, $outline);
    caca_refresh_display($dp);
}