Changeset 3296 for libcaca/trunk/caca-php/examples/cacapig.php
- Timestamp:
- Nov 6, 2008, 8:16:59 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca-php/examples/cacapig.php
r3268 r3296 5 5 * Copyright (c) 2008 Nicolas Vion <nico@yojik.eu> 6 6 * 7 * This file is a Php port of "cxx/c pptest.cpp"7 * This file is a Php port of "cxx/cxxtest.cpp" 8 8 * which is: 9 9 * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org> … … 20 20 die("You have to run this program with php-cli!\n"); 21 21 } 22 23 include dirname($argv[0]) . '/../caca.php'; 22 24 23 25 $pig_str = <<<EOT … … 38 40 EOT; 39 41 40 $canvas = caca_create_canvas(0, 0);42 $canvas = new Canvas(); 41 43 if (!$canvas) { 42 44 die("Error while creating main canvas\n"); 43 45 } 44 46 45 $pig = caca_create_canvas(0, 0);47 $pig = new Canvas(); 46 48 if (!$pig) { 47 49 die("Error while creating canvas pig\n"); 48 50 } 49 51 50 $display = caca_create_display($canvas);52 $display = new Display($canvas); 51 53 if (!$display) { 52 54 die("Error while attaching canvas to display\n"); … … 54 56 55 57 56 caca_set_color_ansi($pig, CACA_LIGHTMAGENTA, CACA_TRANSPARENT); 57 caca_set_color_ansi($canvas, CACA_LIGHTBLUE, CACA_TRANSPARENT); 58 caca_import_string($pig, $pig_str, "text"); 59 caca_set_display_time($display, 30000); 58 $pig->setColorANSI(AnsiColor::LIGHTMAGENTA, AnsiColor::TRANSPARENT); 59 $pig->importString($pig_str, "text"); 60 $display->setDisplayTime(20000); 60 61 61 62 $x = $y = 0; 62 63 $ix = $iy = 1; 63 64 64 while (! caca_get_event($display, CACA_EVENT_KEY_PRESS)) {65 while (! $display->getEvent(EventType::KEY_PRESS)) { 65 66 // In case of resize ... 66 if ($x + caca_get_canvas_width($pig) - 1 >= caca_get_canvas_width($canvas) || $x < 0 )67 if ($x + $pig->getWidth() - 1 >= $canvas->getWidth() || $x < 0 ) 67 68 $x = 0; 68 if ($y + caca_get_canvas_height($pig) - 1 >= caca_get_canvas_height($canvas) || $y < 0 )69 if ($y + $pig->getHeight() - 1 >= $canvas->getHeight() || $y < 0 ) 69 70 $y = 0; 70 71 71 caca_clear_canvas($canvas);72 $canvas->Clear(); 72 73 73 74 // Draw 74 caca_blit($canvas, $x, $y, $pig); 75 caca_put_str($canvas, caca_get_canvas_width($canvas) / 2 - 10, caca_get_canvas_height($canvas) / 2, "Powered by libcaca ".caca_get_version()); 76 caca_refresh_display($display); 75 $canvas->Blit($x, $y, $pig, NULL); 76 $canvas->setColorANSI(AnsiColor::LIGHTBLUE, AnsiColor::BLACK); 77 $canvas->putStr($canvas->getWidth() / 2 - 10, $canvas->getHeight() / 2, "Powered by libcaca ".Libcaca::getVersion()); 78 $display->refresh(); 77 79 78 80 … … 80 82 $x += $ix; 81 83 $y += $iy; 82 if ($x + caca_get_canvas_width($pig) >= caca_get_canvas_width($canvas) || $x < 0 )84 if ($x + $pig->getWidth() >= $canvas->getWidth() || $x < 0 ) 83 85 $ix = -$ix; 84 if ($y + caca_get_canvas_height($pig) >= caca_get_canvas_height($canvas) || $y < 0 )86 if ($y + $pig->getHeight() >= $canvas->getHeight() || $y < 0 ) 85 87 $iy = -$iy; 86 88 }
Note: See TracChangeset
for help on using the changeset viewer.