source: libcaca/trunk/examples/transform.c @ 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:keywords set to Id
File size: 3.4 KB
Line 
1/*
2 *  unicode       libcaca Unicode rendering test program
3 *  Copyright (c) 2006-2009 Sam Hocevar <sam@hocevar.net>
4 *                All Rights Reserved
5 *
6 *  This program is free software. It comes without any warranty, to
7 *  the extent permitted by applicable law. You can redistribute it
8 *  and/or modify it under the terms of the Do What The Fuck You Want
9 *  To Public License, Version 2, as published by Sam Hocevar. See
10 *  http://sam.zoy.org/wtfpl/COPYING for more details.
11 */
12
13#include "config.h"
14
15#if !defined(__KERNEL__)
16#   include <stdio.h>
17#   include <string.h>
18#endif
19
20#include "caca.h"
21
22static char const pig[] =
23    ",--.   ,--.\n"
24    "\\  /-~-\\  /\n"
25    " )' o O `(\n"
26    "(  ,---.  )\n"
27    " `(_o_o_)'\n"
28    "   )`-'(\n";
29
30static char const duck[] =
31    "                ,~~.\n"
32    "    __     ,   (  O )>\n"
33    "___( o)>   )`~~'   (\n"
34    "\\ <_. )   (  .__)   )\n"
35    " `---'     `-.____,'\n";
36
37int main(int argc, char *argv[])
38{
39    caca_canvas_t *cv, *image, *tmp, *sprite;
40    caca_display_t *dp;
41
42    cv = caca_create_canvas(0, 0);
43    if(cv == NULL)
44    {
45        printf("Can't created canvas\n");
46        return -1;
47    }
48    dp = caca_create_display(cv);
49    if(dp == NULL)
50    {
51        printf("Can't create display\n");
52        return -1;
53    }
54
55    image = caca_create_canvas(70, 6);
56    tmp = caca_create_canvas(70, 6);
57    sprite = caca_create_canvas(0, 0);
58
59    caca_set_color_ansi(sprite, CACA_LIGHTMAGENTA, CACA_BLACK);
60    caca_import_canvas_from_memory(sprite, pig, strlen(pig), "text");
61    caca_blit(image, 55, 0, sprite, NULL);
62
63    caca_set_color_ansi(sprite, CACA_LIGHTGREEN, CACA_BLACK);
64    caca_import_canvas_from_memory(sprite, duck, strlen(duck), "text");
65    caca_blit(image, 30, 1, sprite, NULL);
66
67    caca_set_color_ansi(image, CACA_LIGHTCYAN, CACA_BLACK);
68    caca_put_str(image, 1, 1, "hahaha mais vieux porc immonde !! [⽼ ⾗]");
69    caca_set_color_ansi(image, CACA_LIGHTRED, CACA_BLACK);
70    caca_put_char(image, 38, 1, '|');
71
72    caca_set_color_ansi(image, CACA_YELLOW, CACA_BLACK);
73    caca_put_str(image, 4, 2, "\\o\\ \\o| _o/ \\o_ |o/ /o/");
74
75    caca_set_color_ansi(image, CACA_WHITE, CACA_LIGHTRED);
76    caca_put_str(image, 7, 3, "▙▘▌▙▘▞▖▞▖▌ ▞▖▌ ▌▌");
77    caca_put_str(image, 7, 4, "▛▖▌▛▖▚▘▚▘▚▖▚▘▚▖▖▖");
78    caca_set_color_ansi(image, CACA_BLACK, CACA_LIGHTRED);
79    caca_put_str(image, 4, 3, "▓▒░");
80    caca_put_str(image, 4, 4, "▓▒░");
81    caca_put_str(image, 24, 3, "░▒▓");
82    caca_put_str(image, 24, 4, "░▒▓");
83
84    /* Blit the transformed canvas onto the main canvas */
85    caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
86    caca_put_str(cv, 0, 0, "normal");
87    caca_blit(cv, 10, 0, image, NULL);
88
89    caca_put_str(cv, 0, 6, "flip");
90    caca_blit(tmp, 0, 0, image, NULL);
91    caca_flip(tmp);
92    caca_blit(cv, 10, 6, tmp, NULL);
93
94    caca_put_str(cv, 0, 12, "flop");
95    caca_blit(tmp, 0, 0, image, NULL);
96    caca_flop(tmp);
97    caca_blit(cv, 10, 12, tmp, NULL);
98
99    caca_put_str(cv, 0, 18, "rotate");
100    caca_blit(tmp, 0, 0, image, NULL);
101    caca_rotate_180(tmp);
102    caca_blit(cv, 10, 18, tmp, NULL);
103
104    caca_refresh_display(dp);
105
106    caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
107
108    caca_free_display(dp);
109    caca_free_canvas(tmp);
110    caca_free_canvas(sprite);
111    caca_free_canvas(image);
112    caca_free_canvas(cv);
113
114    return 0;
115}
116
Note: See TracBrowser for help on using the repository browser.