[3131] | 1 | #!/usr/bin/php5 |
---|
| 2 | <?php |
---|
[3172] | 3 | /* |
---|
| 4 | * polyline.php sample program for libcaca php binding |
---|
| 5 | * Copyright (c) 2008 Nicolas Vion <nico@yojik.eu> |
---|
| 6 | * |
---|
| 7 | * This program is free software. It comes without any warranty, to |
---|
| 8 | * the extent permitted by applicable law. You can redistribute it |
---|
| 9 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
| 10 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
| 11 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
| 12 | */ |
---|
[3131] | 13 | |
---|
[3132] | 14 | function transform($tbl, $tx, $ty, $sx, $sy) { |
---|
| 15 | $result = array(); |
---|
| 16 | foreach($tbl as $pt) |
---|
| 17 | $result[] = array($pt[0] * $sx + $tx, $pt[1] * $sy + $ty); |
---|
| 18 | return $result; |
---|
| 19 | } |
---|
| 20 | |
---|
[3177] | 21 | if (php_sapi_name() != "cli") { |
---|
[3175] | 22 | die("You have to run this program with php-cli!\n"); |
---|
[3177] | 23 | } |
---|
[3175] | 24 | |
---|
[3131] | 25 | $canvas = caca_create_canvas(0, 0); |
---|
| 26 | $display = caca_create_display($canvas); |
---|
| 27 | if (!$display) { |
---|
| 28 | die("Error while attaching canvas to display\n"); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | $tbl = array( |
---|
| 32 | array(5, 2), |
---|
| 33 | array(15, 2), |
---|
| 34 | array(20, 4), |
---|
| 35 | array(25, 2), |
---|
| 36 | array(34, 2), |
---|
| 37 | array(37, 4), |
---|
| 38 | array(36, 9), |
---|
| 39 | array(20, 16), |
---|
| 40 | array(3, 9), |
---|
| 41 | array(2, 4), |
---|
| 42 | array(5, 2) |
---|
| 43 | ); |
---|
| 44 | |
---|
| 45 | for ($i = 0; $i < 10; $i++) { |
---|
| 46 | caca_set_color_ansi($canvas, 1 + (($color += 4) % 15), CACA_TRANSPARENT); |
---|
| 47 | $scale = caca_rand(4, 10) / 10; |
---|
[3132] | 48 | $translate = array(caca_rand(-5, 55), caca_rand(-2, 25)); |
---|
[3131] | 49 | $pts = transform($tbl, $translate[0], $translate[1], $scale, $scale); |
---|
| 50 | caca_draw_thin_polyline($canvas, $pts); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | caca_put_str($canvas, 1, 1, "Caca forever..."); |
---|
| 54 | caca_refresh_display($display); |
---|
[3174] | 55 | caca_get_event($display, CACA_EVENT_KEY_PRESS, 5000000); |
---|
[3132] | 56 | |
---|
[3135] | 57 | ?> |
---|