Ejemplo n.º 1
0
Archivo: caca.php Proyecto: dns/libcaca
 function refresh()
 {
     return caca_refresh_display($this->dp);
 }
Ejemplo n.º 2
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);
Ejemplo n.º 3
0
 *
 *  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");
}
$imports = caca_get_import_list();
if ($argc < 2 || $argc > 3) {
    $msg = $argv[0] . ": wrong argument count\n" . "usage: " . $argv[0] . " file [<format>]\n" . "where <format> is one of:\n";
    foreach ($imports as $format => $name) {
        $msg .= " \"" . $name . "\" (" . $format . ")\n";
    }
    die($msg);
}
$cv = caca_create_canvas(0, 0);
if (!$cv) {
    die("Can't create canvas\n");
}
if (caca_import_file($cv, $argv[1], $argc >= 3 ? $argv[2] : "") < 0) {
    die($argv[0] . ": could not open `" . $argv[1] . "'.\n");
}
$dp = caca_create_display($cv);
if (!$dp) {
    die("Can't create display\n");
}
caca_refresh_display($dp);
caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1);
Ejemplo n.º 4
0
Archivo: demo.php Proyecto: dns/libcaca
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);
}