1 | #!/usr/bin/php5 |
---|
2 | <?php |
---|
3 | /* |
---|
4 | * transform transformation test program |
---|
5 | * Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com> |
---|
6 | * |
---|
7 | * This file is a Php port of "examples/transform.c" |
---|
8 | * which is: |
---|
9 | * Copyright (c) 2006 Sam Hocevar <sam@hocevar.net> |
---|
10 | * All Rights Reserved |
---|
11 | * |
---|
12 | * $Id: transform.php 4148 2009-12-19 14:38:38Z sam $ |
---|
13 | * |
---|
14 | * This program is free software. It comes without any warranty, to |
---|
15 | * the extent permitted by applicable law. You can redistribute it |
---|
16 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
17 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
18 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
19 | */ |
---|
20 | |
---|
21 | if (php_sapi_name() != "cli") { |
---|
22 | die("You have to run this program with php-cli!\n"); |
---|
23 | } |
---|
24 | |
---|
25 | $pig = ( |
---|
26 | ",--. ,--.\n" . |
---|
27 | "\\ /-~-\\ /\n" . |
---|
28 | " )' o O `(\n" . |
---|
29 | "( ,---. )\n" . |
---|
30 | " `(_o_o_)'\n" . |
---|
31 | " )`-'(\n"); |
---|
32 | |
---|
33 | $duck = ( |
---|
34 | " ,~~.\n" . |
---|
35 | " __ , ( O )>\n" . |
---|
36 | "___( o)> )`~~' (\n" . |
---|
37 | "\\ <_. ) ( .__) )\n" . |
---|
38 | " `---' `-.____,'\n"); |
---|
39 | |
---|
40 | $cv = caca_create_canvas(0, 0); |
---|
41 | if(! $cv) |
---|
42 | { |
---|
43 | die("Can't created canvas\n"); |
---|
44 | } |
---|
45 | $dp = caca_create_display($cv); |
---|
46 | if(! $dp) |
---|
47 | { |
---|
48 | die("Can't create display\n"); |
---|
49 | } |
---|
50 | |
---|
51 | $image = caca_create_canvas(70, 6); |
---|
52 | $tmp = caca_create_canvas(70, 6); |
---|
53 | $sprite = caca_create_canvas(0, 0); |
---|
54 | |
---|
55 | caca_set_color_ansi($sprite, CACA_LIGHTMAGENTA, CACA_BLACK); |
---|
56 | caca_import_string($sprite, $pig, "text"); |
---|
57 | caca_blit($image, 55, 0, $sprite); |
---|
58 | |
---|
59 | caca_set_color_ansi($sprite, CACA_LIGHTGREEN, CACA_BLACK); |
---|
60 | caca_import_string($sprite, $duck, "text"); |
---|
61 | caca_blit($image, 30, 1, $sprite); |
---|
62 | |
---|
63 | caca_set_color_ansi($image, CACA_LIGHTCYAN, CACA_BLACK); |
---|
64 | caca_put_str($image, 1, 1, "hahaha mais vieux porc immonde !! [⽼ ⾗]"); |
---|
65 | caca_set_color_ansi($image, CACA_LIGHTRED, CACA_BLACK); |
---|
66 | caca_put_char($image, 38, 1, ord('|')); |
---|
67 | |
---|
68 | caca_set_color_ansi($image, CACA_YELLOW, CACA_BLACK); |
---|
69 | caca_put_str($image, 4, 2, "\\o\\ \\o| _o/ \\o_ |o/ /o/"); |
---|
70 | |
---|
71 | caca_set_color_ansi($image, CACA_WHITE, CACA_LIGHTRED); |
---|
72 | caca_put_str($image, 7, 3, "▙▘▌▙▘▞▖▞▖▌ ▞▖▌ ▌▌"); |
---|
73 | caca_put_str($image, 7, 4, "▛▖▌▛▖▚▘▚▘▚▖▚▘▚▖▖▖"); |
---|
74 | caca_set_color_ansi($image, CACA_BLACK, CACA_LIGHTRED); |
---|
75 | caca_put_str($image, 4, 3, "▓▒░"); |
---|
76 | caca_put_str($image, 4, 4, "▓▒░"); |
---|
77 | caca_put_str($image, 24, 3, "░▒▓"); |
---|
78 | caca_put_str($image, 24, 4, "░▒▓"); |
---|
79 | |
---|
80 | /* Blit the transformed canvas onto the main canvas */ |
---|
81 | caca_set_color_ansi($cv, CACA_WHITE, CACA_BLUE); |
---|
82 | caca_put_str($cv, 0, 0, "normal"); |
---|
83 | caca_blit($cv, 10, 0, $image); |
---|
84 | |
---|
85 | caca_put_str($cv, 0, 6, "flip"); |
---|
86 | caca_blit($tmp, 0, 0, $image); |
---|
87 | caca_flip($tmp); |
---|
88 | caca_blit($cv, 10, 6, $tmp); |
---|
89 | |
---|
90 | caca_put_str($cv, 0, 12, "flop"); |
---|
91 | caca_blit($tmp, 0, 0, $image); |
---|
92 | caca_flop($tmp); |
---|
93 | caca_blit($cv, 10, 12, $tmp); |
---|
94 | |
---|
95 | caca_put_str($cv, 0, 18, "rotate"); |
---|
96 | caca_blit($tmp, 0, 0, $image); |
---|
97 | caca_rotate_180($tmp); |
---|
98 | caca_blit($cv, 10, 18, $tmp); |
---|
99 | |
---|
100 | caca_refresh_display($dp); |
---|
101 | |
---|
102 | caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1); |
---|
103 | ?> |
---|