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"); }
* 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);
static function Rand($min, $max) { return caca_rand($min, $max); }
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('#')); } } }