source: libcaca/trunk/caca-php/examples/polyline.php @ 3131

Last change on this file since 3131 was 3131, checked in by nico, 12 years ago
  • Add php binding for caca_draw_polyline and caca_draw_thin_polyline
  • Add a sample program examples/polyline.php
  • Property svn:executable set to *
File size: 923 bytes
Line 
1#!/usr/bin/php5
2<?php
3
4$canvas = caca_create_canvas(0, 0);
5$display = caca_create_display($canvas);
6if (!$display) {
7        die("Error while attaching canvas to display\n");
8}
9
10$tbl = array(
11        array(5, 2),
12        array(15, 2),
13        array(20, 4),
14        array(25, 2),
15        array(34, 2),
16        array(37, 4),
17        array(36, 9),
18        array(20, 16),
19        array(3, 9),
20        array(2, 4),
21        array(5, 2)
22);
23
24function transform($tbl, $tx, $ty, $sx, $sy) {
25        $result = array();
26        foreach($tbl as $pt)
27                $result[] = array($pt[0] * $sx + $tx, $pt[1] * $sy + $ty);
28        return $result;
29}
30
31for ($i = 0; $i < 10; $i++) {
32        caca_set_color_ansi($canvas, 1 + (($color += 4) % 15), CACA_TRANSPARENT);
33        $scale = caca_rand(4, 10) / 10;
34        $translate = array(caca_rand(-10, 60), caca_rand(-5, 20));
35        $pts = transform($tbl, $translate[0], $translate[1], $scale, $scale);
36        caca_draw_thin_polyline($canvas, $pts);
37}
38
39caca_put_str($canvas, 1, 1, "Caca forever...");
40caca_refresh_display($display);
41sleep(5);
Note: See TracBrowser for help on using the repository browser.