diff --git a/caca-php/examples/transform.php b/caca-php/examples/transform.php old mode 100644 new mode 100755 index 6c6827a..9165b6f --- a/caca-php/examples/transform.php +++ b/caca-php/examples/transform.php @@ -1,5 +1,11 @@ +#!/usr/bin/php5 + + * + * This file is a Php port of "examples/transform.c" + * which is: * Copyright (c) 2006 Sam Hocevar * All Rights Reserved * @@ -12,107 +18,86 @@ * http://sam.zoy.org/wtfpl/COPYING for more details. */ -#include "config.h" - -#if !defined(__KERNEL__) -# include -# include -#endif - -#include "caca.h" - -static char const pig[] = - ",--. ,--.\n" - "\\ /-~-\\ /\n" - " )' o O `(\n" - "( ,---. )\n" - " `(_o_o_)'\n" - " )`-'(\n"; - -static char const duck[] = - " ,~~.\n" - " __ , ( O )>\n" - "___( o)> )`~~' (\n" - "\\ <_. ) ( .__) )\n" - " `---' `-.____,'\n"; +if (php_sapi_name() != "cli") { + die("You have to run this program with php-cli!\n"); +} -int main(int argc, char *argv[]) +$pig = ( + ",--. ,--.\n" . + "\\ /-~-\\ /\n" . + " )' o O `(\n" . + "( ,---. )\n" . + " `(_o_o_)'\n" . + " )`-'(\n"); + +$duck = ( + " ,~~.\n" . + " __ , ( O )>\n" . + "___( o)> )`~~' (\n" . + "\\ <_. ) ( .__) )\n" . + " `---' `-.____,'\n"); + +$cv = caca_create_canvas(0, 0); +if(! $cv) +{ + die("Can't created canvas\n"); +} +$dp = caca_create_display($cv); +if(! $dp) { - caca_canvas_t *cv, *image, *tmp, *sprite; - caca_display_t *dp; - - cv = caca_create_canvas(0, 0); - if(cv == NULL) - { - printf("Can't created canvas\n"); - return -1; - } - dp = caca_create_display(cv); - if(dp == NULL) - { - printf("Can't create display\n"); - return -1; - } - - image = caca_create_canvas(70, 6); - tmp = caca_create_canvas(70, 6); - sprite = caca_create_canvas(0, 0); - - caca_set_color_ansi(sprite, CACA_LIGHTMAGENTA, CACA_BLACK); - caca_import_memory(sprite, pig, strlen(pig), "text"); - caca_blit(image, 55, 0, sprite, NULL); - - caca_set_color_ansi(sprite, CACA_LIGHTGREEN, CACA_BLACK); - caca_import_memory(sprite, duck, strlen(duck), "text"); - caca_blit(image, 30, 1, sprite, NULL); - - caca_set_color_ansi(image, CACA_LIGHTCYAN, CACA_BLACK); - caca_put_str(image, 1, 1, "hahaha mais vieux porc immonde !! [⽼ ⾗]"); - caca_set_color_ansi(image, CACA_LIGHTRED, CACA_BLACK); - caca_put_char(image, 38, 1, '|'); - - caca_set_color_ansi(image, CACA_YELLOW, CACA_BLACK); - caca_put_str(image, 4, 2, "\\o\\ \\o| _o/ \\o_ |o/ /o/"); - - caca_set_color_ansi(image, CACA_WHITE, CACA_LIGHTRED); - caca_put_str(image, 7, 3, "▙▘▌▙▘▞▖▞▖▌ ▞▖▌ ▌▌"); - caca_put_str(image, 7, 4, "▛▖▌▛▖▚▘▚▘▚▖▚▘▚▖▖▖"); - caca_set_color_ansi(image, CACA_BLACK, CACA_LIGHTRED); - caca_put_str(image, 4, 3, "▓▒░"); - caca_put_str(image, 4, 4, "▓▒░"); - caca_put_str(image, 24, 3, "░▒▓"); - caca_put_str(image, 24, 4, "░▒▓"); - - /* Blit the transformed canvas onto the main canvas */ - caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE); - caca_put_str(cv, 0, 0, "normal"); - caca_blit(cv, 10, 0, image, NULL); - - caca_put_str(cv, 0, 6, "flip"); - caca_blit(tmp, 0, 0, image, NULL); - caca_flip(tmp); - caca_blit(cv, 10, 6, tmp, NULL); - - caca_put_str(cv, 0, 12, "flop"); - caca_blit(tmp, 0, 0, image, NULL); - caca_flop(tmp); - caca_blit(cv, 10, 12, tmp, NULL); - - caca_put_str(cv, 0, 18, "rotate"); - caca_blit(tmp, 0, 0, image, NULL); - caca_rotate_180(tmp); - caca_blit(cv, 10, 18, tmp, NULL); - - caca_refresh_display(dp); - - caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); - - caca_free_display(dp); - caca_free_canvas(tmp); - caca_free_canvas(sprite); - caca_free_canvas(image); - caca_free_canvas(cv); - - return 0; + die("Can't create display\n"); } +$image = caca_create_canvas(70, 6); +$tmp = caca_create_canvas(70, 6); +$sprite = caca_create_canvas(0, 0); + +caca_set_color_ansi($sprite, CACA_LIGHTMAGENTA, CACA_BLACK); +caca_import_string($sprite, $pig, "text"); +caca_blit($image, 55, 0, $sprite); + +caca_set_color_ansi($sprite, CACA_LIGHTGREEN, CACA_BLACK); +caca_import_string($sprite, $duck, "text"); +caca_blit($image, 30, 1, $sprite); + +caca_set_color_ansi($image, CACA_LIGHTCYAN, CACA_BLACK); +caca_put_str($image, 1, 1, "hahaha mais vieux porc immonde !! [⽼ ⾗]"); +caca_set_color_ansi($image, CACA_LIGHTRED, CACA_BLACK); +caca_put_char($image, 38, 1, ord('|')); + +caca_set_color_ansi($image, CACA_YELLOW, CACA_BLACK); +caca_put_str($image, 4, 2, "\\o\\ \\o| _o/ \\o_ |o/ /o/"); + +caca_set_color_ansi($image, CACA_WHITE, CACA_LIGHTRED); +caca_put_str($image, 7, 3, "▙▘▌▙▘▞▖▞▖▌ ▞▖▌ ▌▌"); +caca_put_str($image, 7, 4, "▛▖▌▛▖▚▘▚▘▚▖▚▘▚▖▖▖"); +caca_set_color_ansi($image, CACA_BLACK, CACA_LIGHTRED); +caca_put_str($image, 4, 3, "▓▒░"); +caca_put_str($image, 4, 4, "▓▒░"); +caca_put_str($image, 24, 3, "░▒▓"); +caca_put_str($image, 24, 4, "░▒▓"); + +/* Blit the transformed canvas onto the main canvas */ +caca_set_color_ansi($cv, CACA_WHITE, CACA_BLUE); +caca_put_str($cv, 0, 0, "normal"); +caca_blit($cv, 10, 0, $image); + +caca_put_str($cv, 0, 6, "flip"); +caca_blit($tmp, 0, 0, $image); +caca_flip($tmp); +caca_blit($cv, 10, 6, $tmp); + +caca_put_str($cv, 0, 12, "flop"); +caca_blit($tmp, 0, 0, $image); +caca_flop($tmp); +caca_blit($cv, 10, 12, $tmp); + +caca_put_str($cv, 0, 18, "rotate"); +caca_blit($tmp, 0, 0, $image); +caca_rotate_180($tmp); +caca_blit($cv, 10, 18, $tmp); + +caca_refresh_display($dp); + +caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1); +?>