source: libcaca/trunk/caca-php/examples/transform.php @ 4333

Last change on this file since 4333 was 4333, checked in by Sam Hocevar, 10 years ago

Large source code cleanup, getting rid of spaces, tabs, and svn keywords.

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
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 *  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://sam.zoy.org/wtfpl/COPYING for more details.
17 */
18
19if (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);
39if(! $cv)
40{
41    die("Can't created canvas\n");
42}
43$dp = caca_create_display($cv);
44if(! $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
53caca_set_color_ansi($sprite, CACA_LIGHTMAGENTA, CACA_BLACK);
54caca_import_string($sprite, $pig, "text");
55caca_blit($image, 55, 0, $sprite);
56
57caca_set_color_ansi($sprite, CACA_LIGHTGREEN, CACA_BLACK);
58caca_import_string($sprite, $duck, "text");
59caca_blit($image, 30, 1, $sprite);
60
61caca_set_color_ansi($image, CACA_LIGHTCYAN, CACA_BLACK);
62caca_put_str($image, 1, 1, "hahaha mais vieux porc immonde !! [⽼ ⾗]");
63caca_set_color_ansi($image, CACA_LIGHTRED, CACA_BLACK);
64caca_put_char($image, 38, 1, ord('|'));
65
66caca_set_color_ansi($image, CACA_YELLOW, CACA_BLACK);
67caca_put_str($image, 4, 2, "\\o\\ \\o| _o/ \\o_ |o/ /o/");
68
69caca_set_color_ansi($image, CACA_WHITE, CACA_LIGHTRED);
70caca_put_str($image, 7, 3, "▙▘▌▙▘▞▖▞▖▌ ▞▖▌ ▌▌");
71caca_put_str($image, 7, 4, "▛▖▌▛▖▚▘▚▘▚▖▚▘▚▖▖▖");
72caca_set_color_ansi($image, CACA_BLACK, CACA_LIGHTRED);
73caca_put_str($image, 4, 3, "▓▒░");
74caca_put_str($image, 4, 4, "▓▒░");
75caca_put_str($image, 24, 3, "░▒▓");
76caca_put_str($image, 24, 4, "░▒▓");
77
78/* Blit the transformed canvas onto the main canvas */
79caca_set_color_ansi($cv, CACA_WHITE, CACA_BLUE);
80caca_put_str($cv, 0, 0, "normal");
81caca_blit($cv, 10, 0, $image);
82
83caca_put_str($cv, 0, 6, "flip");
84caca_blit($tmp, 0, 0, $image);
85caca_flip($tmp);
86caca_blit($cv, 10, 6, $tmp);
87
88caca_put_str($cv, 0, 12, "flop");
89caca_blit($tmp, 0, 0, $image);
90caca_flop($tmp);
91caca_blit($cv, 10, 12, $tmp);
92
93caca_put_str($cv, 0, 18, "rotate");
94caca_blit($tmp, 0, 0, $image);
95caca_rotate_180($tmp);
96caca_blit($cv, 10, 18, $tmp);
97
98caca_refresh_display($dp);
99
100caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1);
101?>
Note: See TracBrowser for help on using the repository browser.