コード例 #1
0
ファイル: test.php プロジェクト: dns/libcaca
 static function Main()
 {
     printf("libcaca %s PHP test\n", Libcaca::getVersion());
     printf("(c) 2006 Jean-Yves Lamoureux <*****@*****.**>\n");
     printf("(c) 2007 Sam Hocevar <*****@*****.**>\n");
     printf("(c) 2008 Benjamin C. Wiley Sittler <*****@*****.**>\n");
     /* Instanciate a caca canvas */
     $cv = new DemoCanvas();
     /* We have a proper canvas, let's display it using Caca */
     $dp = new DemoDisplay($cv);
     /* Random number. This is a static method,
        not to be used with previous instance */
     printf("A random number: %d\n", Libcaca::Rand(0, 1337));
     $dp->EventLoop();
 }
コード例 #2
0
ファイル: cacapig.php プロジェクト: dns/libcaca
    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;
    }
}