Debian Codegraph @

caca-php/examples/transform.php

raw
1 #!/usr/bin/php5
2 <?php
3 /*
4 * transform transformation test program
5 * Copyright (c) 2008 Benjamin C. Wiley Sittler <[email protected]>
6 *
7 * This file is a Php port of "examples/transform.c"
8 * which is:
9 * Copyright (c) 2006 Sam Hocevar <[email protected]>
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://www.wtfpl.net/ for more details.
17 */
18
19 if (php_sapi_name() != "cli") {
20 die("You have to run this program with php-cli!\n");
21 }
22
23 $pig = (
24 ",--. ,--.\n" .
25 "\\ /-~-\\ /\n" .
26 " )' o O `(\n" .
27 "( ,---. )\n" .
28 " `(_o_o_)'\n" .
29 " )`-'(\n");
30
31 $duck = (
32 " ,~~.\n" .
33 " __ , ( O )>\n" .
34 "___( o)> )`~~' (\n" .
35 "\\ <_. ) ( .__) )\n" .
36 " `---' `-.____,'\n");
37
38 $cv = caca_create_canvas(0, 0);
39 if(! $cv)
40 {
41 die("Can't created canvas\n");
42 }
43 $dp = caca_create_display($cv);
44 if(! $dp)
45 {
46 die("Can't create display\n");
47 }
48
49 $image = caca_create_canvas(70, 6);
50 $tmp = caca_create_canvas(70, 6);
51 $sprite = caca_create_canvas(0, 0);
52
53 caca_set_color_ansi($sprite, CACA_LIGHTMAGENTA, CACA_BLACK);
54 caca_import_string($sprite, $pig, "text");
55 caca_blit($image, 55, 0, $sprite);
56
57 caca_set_color_ansi($sprite, CACA_LIGHTGREEN, CACA_BLACK);
58 caca_import_string($sprite, $duck, "text");
59 caca_blit($image, 30, 1, $sprite);
60
61 caca_set_color_ansi($image, CACA_LIGHTCYAN, CACA_BLACK);
62 caca_put_str($image, 1, 1, "hahaha mais vieux porc immonde !! [⽼ ⾗]");
63 caca_set_color_ansi($image, CACA_LIGHTRED, CACA_BLACK);
64 caca_put_char($image, 38, 1, ord('|'));
65
66 caca_set_color_ansi($image, CACA_YELLOW, CACA_BLACK);
67 caca_put_str($image, 4, 2, "\\o\\ \\o| _o/ \\o_ |o/ /o/");
68
69 caca_set_color_ansi($image, CACA_WHITE, CACA_LIGHTRED);
70 caca_put_str($image, 7, 3, "▙▘▌▙▘▞▖▞▖▌ ▞▖▌ ▌▌");
71 caca_put_str($image, 7, 4, "▛▖▌▛▖▚▘▚▘▚▖▚▘▚▖▖▖");
72 caca_set_color_ansi($image, CACA_BLACK, CACA_LIGHTRED);
73 caca_put_str($image, 4, 3, "▓▒░");
74 caca_put_str($image, 4, 4, "▓▒░");
75 caca_put_str($image, 24, 3, "░▒▓");
76 caca_put_str($image, 24, 4, "░▒▓");
77
78 /* Blit the transformed canvas onto the main canvas */
79 caca_set_color_ansi($cv, CACA_WHITE, CACA_BLUE);
80 caca_put_str($cv, 0, 0, "normal");
81 caca_blit($cv, 10, 0, $image);
82
83 caca_put_str($cv, 0, 6, "flip");
84 caca_blit($tmp, 0, 0, $image);
85 caca_flip($tmp);
86 caca_blit($cv, 10, 6, $tmp);
87
88 caca_put_str($cv, 0, 12, "flop");
89 caca_blit($tmp, 0, 0, $image);
90 caca_flop($tmp);
91 caca_blit($cv, 10, 12, $tmp);
92
93 caca_put_str($cv, 0, 18, "rotate");
94 caca_blit($tmp, 0, 0, $image);
95 caca_rotate_180($tmp);
96 caca_blit($cv, 10, 18, $tmp);
97
98 caca_refresh_display($dp);
99
100 caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1);
101 ?>