source: libcaca/trunk/caca-php/examples/cacapig.php @ 3135

Last change on this file since 3135 was 3135, checked in by nico, 15 years ago
  • Close php blocks in samples programs (add "?>")
  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#!/usr/bin/php5
2<?php
3
4$pig_str = <<<EOT
5                                   
6    _._ _..._ .-',     _.._(`))   
7   '-. `     '  /-._.-'    ',/     
8      )         \            '.   
9     / _    _    |             \   
10    |  a    a    /   PHP        | 
11    \   .-.                     ;
12     '-('' ).-'       ,'       ;   
13        '-;           |      .'   
14           \           \    /   
15           | 7  .__  _.-\   \   
16           | |  |  ``/  /`  /     
17      jgs /,_|  |   /,_/   /       
18             /,_/      '`-'       
19EOT;
20
21$canvas = caca_create_canvas(0, 0);
22if (!$canvas) {
23        die("Error while creating main canvas\n");
24}
25
26$pig = caca_create_canvas(0, 0);
27if (!$pig) {
28        die("Error while creating canvas pig\n");
29}
30
31$display = caca_create_display($canvas);
32if (!$display) {
33        die("Error while attaching canvas to display\n");
34}
35
36
37caca_set_color_ansi($pig, CACA_LIGHTMAGENTA, CACA_TRANSPARENT);
38caca_set_color_ansi($canvas, CACA_LIGHTBLUE, CACA_TRANSPARENT);
39caca_import_string($pig, $pig_str, "text");
40caca_set_display_time($display, 30000);
41
42$x = $y = 0;
43$ix = $iy = 1;
44
45while (!caca_get_event($display, CACA_EVENT_KEY_PRESS)) {
46        // In case of resize ...
47        if ($x + caca_get_canvas_width($pig) - 1 >= caca_get_canvas_width($canvas) || $x < 0 )
48                $x = 0;
49        if ($y + caca_get_canvas_height($pig) - 1 >= caca_get_canvas_height($canvas) || $y < 0 )
50                $y = 0;
51
52        caca_clear_canvas($canvas);
53
54        // Draw
55        caca_blit($canvas, $x, $y, $pig);
56        caca_put_str($canvas, caca_get_canvas_width($canvas) / 2 - 10, caca_get_canvas_height($canvas) / 2, "Powered by libcaca ".caca_get_version());
57        caca_refresh_display($display);
58
59
60        // Move cursor
61        $x += $ix;
62        $y += $iy;
63        if ($x + caca_get_canvas_width($pig) >= caca_get_canvas_width($canvas) || $x < 0 )
64                $ix = -$ix;
65        if ($y + caca_get_canvas_height($pig) >= caca_get_canvas_height($canvas) || $y < 0 )
66                $iy = -$iy;
67}
68
69?>
Note: See TracBrowser for help on using the repository browser.