[3089] | 1 | #!/usr/bin/php5 |
---|
[3126] | 2 | <?php |
---|
[3172] | 3 | /* |
---|
| 4 | * cacapig.php sample program for libcaca php binding |
---|
| 5 | * Copyright (c) 2008 Nicolas Vion <nico@yojik.eu> |
---|
| 6 | * |
---|
| 7 | * This file is a Php port of "cxx/cpptest.cpp" |
---|
| 8 | * which is: |
---|
| 9 | * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org> |
---|
| 10 | * All Rights Reserved |
---|
| 11 | * |
---|
| 12 | * This program is free software. It comes without any warranty, to |
---|
| 13 | * the extent permitted by applicable law. You can redistribute it |
---|
| 14 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
| 15 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
| 16 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
| 17 | */ |
---|
[3089] | 18 | |
---|
[3172] | 19 | |
---|
[3104] | 20 | $pig_str = <<<EOT |
---|
| 21 | |
---|
| 22 | _._ _..._ .-', _.._(`)) |
---|
| 23 | '-. ` ' /-._.-' ',/ |
---|
| 24 | ) \ '. |
---|
| 25 | / _ _ | \ |
---|
| 26 | | a a / PHP | |
---|
| 27 | \ .-. ; |
---|
| 28 | '-('' ).-' ,' ; |
---|
| 29 | '-; | .' |
---|
| 30 | \ \ / |
---|
| 31 | | 7 .__ _.-\ \ |
---|
| 32 | | | | ``/ /` / |
---|
| 33 | jgs /,_| | /,_/ / |
---|
| 34 | /,_/ '`-' |
---|
| 35 | EOT; |
---|
| 36 | |
---|
| 37 | $canvas = caca_create_canvas(0, 0); |
---|
| 38 | if (!$canvas) { |
---|
| 39 | die("Error while creating main canvas\n"); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | $pig = caca_create_canvas(0, 0); |
---|
| 43 | if (!$pig) { |
---|
| 44 | die("Error while creating canvas pig\n"); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | $display = caca_create_display($canvas); |
---|
| 48 | if (!$display) { |
---|
| 49 | die("Error while attaching canvas to display\n"); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | |
---|
[3105] | 53 | caca_set_color_ansi($pig, CACA_LIGHTMAGENTA, CACA_TRANSPARENT); |
---|
[3106] | 54 | caca_set_color_ansi($canvas, CACA_LIGHTBLUE, CACA_TRANSPARENT); |
---|
[3111] | 55 | caca_import_string($pig, $pig_str, "text"); |
---|
[3105] | 56 | caca_set_display_time($display, 30000); |
---|
[3104] | 57 | |
---|
[3105] | 58 | $x = $y = 0; |
---|
| 59 | $ix = $iy = 1; |
---|
[3104] | 60 | |
---|
[3110] | 61 | while (!caca_get_event($display, CACA_EVENT_KEY_PRESS)) { |
---|
[3105] | 62 | // In case of resize ... |
---|
| 63 | if ($x + caca_get_canvas_width($pig) - 1 >= caca_get_canvas_width($canvas) || $x < 0 ) |
---|
| 64 | $x = 0; |
---|
| 65 | if ($y + caca_get_canvas_height($pig) - 1 >= caca_get_canvas_height($canvas) || $y < 0 ) |
---|
| 66 | $y = 0; |
---|
[3104] | 67 | |
---|
[3105] | 68 | caca_clear_canvas($canvas); |
---|
| 69 | |
---|
[3106] | 70 | // Draw |
---|
[3105] | 71 | caca_blit($canvas, $x, $y, $pig); |
---|
[3106] | 72 | caca_put_str($canvas, caca_get_canvas_width($canvas) / 2 - 10, caca_get_canvas_height($canvas) / 2, "Powered by libcaca ".caca_get_version()); |
---|
[3105] | 73 | caca_refresh_display($display); |
---|
| 74 | |
---|
[3106] | 75 | |
---|
| 76 | // Move cursor |
---|
[3105] | 77 | $x += $ix; |
---|
| 78 | $y += $iy; |
---|
| 79 | if ($x + caca_get_canvas_width($pig) >= caca_get_canvas_width($canvas) || $x < 0 ) |
---|
| 80 | $ix = -$ix; |
---|
| 81 | if ($y + caca_get_canvas_height($pig) >= caca_get_canvas_height($canvas) || $y < 0 ) |
---|
| 82 | $iy = -$iy; |
---|
| 83 | } |
---|
| 84 | |
---|
[3135] | 85 | ?> |
---|