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

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

Update my e-mail address everywhere.

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