Exemplo n.º 1
0
    die("Error while attaching canvas to display\n");
}
$pig->setColorANSI(AnsiColor::LIGHTMAGENTA, AnsiColor::TRANSPARENT);
$pig->importString($pig_str, "text");
$display->setDisplayTime(20000);
$x = $y = 0;
$ix = $iy = 1;
while (!$display->getEvent(EventType::KEY_PRESS)) {
    // In case of resize ...
    if ($x + $pig->getWidth() - 1 >= $canvas->getWidth() || $x < 0) {
        $x = 0;
    }
    if ($y + $pig->getHeight() - 1 >= $canvas->getHeight() || $y < 0) {
        $y = 0;
    }
    $canvas->Clear();
    // Draw
    $canvas->Blit($x, $y, $pig, NULL);
    $canvas->setColorANSI(AnsiColor::LIGHTBLUE, AnsiColor::BLACK);
    $canvas->putStr($canvas->getWidth() / 2 - 10, $canvas->getHeight() / 2, "Powered by libcaca " . Libcaca::getVersion());
    $display->refresh();
    // Move cursor
    $x += $ix;
    $y += $iy;
    if ($x + $pig->getWidth() >= $canvas->getWidth() || $x < 0) {
        $ix = -$ix;
    }
    if ($y + $pig->getHeight() >= $canvas->getHeight() || $y < 0) {
        $iy = -$iy;
    }
}