Ignore:
Timestamp:
Oct 26, 2008, 1:40:00 AM (11 years ago)
Author:
nico
Message:
  • Add Php binding for caca's functions: caca_get_event, caca_set_display_time
  • Animate pink pig & add event managment in sample program "example1.php"
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca-php/examples/example1.php

    r3104 r3105  
    3535
    3636
    37 caca_set_color_ansi($pig, CACA_LIGHTRED, CACA_WHITE);
     37caca_set_color_ansi($pig, CACA_LIGHTMAGENTA, CACA_TRANSPARENT);
    3838caca_import_memory($pig, $pig_str, "text");
    39 caca_blit($canvas, caca_get_canvas_width($canvas) / 2 - 20, caca_get_canvas_height($canvas) /2 - 7, $pig);
    40 caca_refresh_display($display);
     39caca_set_display_time($display, 30000);
    4140
    42 sleep(5);
     41$x = $y = 0;
     42$ix = $iy = 1;
    4343
     44while (caca_get_event($display, CACA_EVENT_KEY_PRESS)) {
     45        // In case of resize ...
     46        if ($x + caca_get_canvas_width($pig) - 1 >= caca_get_canvas_width($canvas) || $x < 0 )
     47                $x = 0;
     48        if ($y + caca_get_canvas_height($pig) - 1 >= caca_get_canvas_height($canvas) || $y < 0 )
     49                $y = 0;
    4450
     51        caca_clear_canvas($canvas);
     52
     53        // Draw pig
     54        caca_blit($canvas, $x, $y, $pig);
     55        caca_refresh_display($display);
     56
     57        $x += $ix;
     58        $y += $iy;
     59
     60        if ($x + caca_get_canvas_width($pig) >= caca_get_canvas_width($canvas) || $x < 0 )
     61                $ix = -$ix;
     62        if ($y + caca_get_canvas_height($pig) >= caca_get_canvas_height($canvas) || $y < 0 )
     63                $iy = -$iy;
     64}
     65
Note: See TracChangeset for help on using the changeset viewer.