source: libcaca/trunk/examples/text.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: 2.4 KB
RevLine 
[843]1/*
2 *  text          canvas text import/export
[3495]3 *  Copyright (c) 2006-2009 Sam Hocevar <sam@hocevar.net>
[843]4 *                All Rights Reserved
5 *
[1462]6 *  This program is free software. It comes without any warranty, to
[1452]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
[843]10 *  http://sam.zoy.org/wtfpl/COPYING for more details.
11 */
12
13#include "config.h"
[2299]14
[1048]15#if !defined(__KERNEL__)
16#   include <stdio.h>
17#   include <string.h>
[1308]18#   include <stdlib.h>
[843]19#endif
[2299]20
[2821]21#include "caca.h"
[843]22
23#define STRING \
[1808]24  "              |_| \n" \
25  "   _,----._   | | \n" \
26  "  (/ @  @ \\)   __ \n" \
27  "   |  OO  |   |_  \n" \
28  "   \\ `--' /   |__ \n" \
29  "    `----'        \n" \
30  "              |_| \n" \
31  " Hello world!  |  \n" \
32  "                  \n"
[843]33
[1048]34int main(int argc, char *argv[])
[843]35{
[2821]36    caca_canvas_t *cv, *pig;
[1308]37    void *buffer;
[2305]38    size_t len;
39    int i, j;
[843]40
[2821]41    pig = caca_create_canvas(0, 0);
[3495]42    caca_import_canvas_from_memory(pig, STRING, strlen(STRING), "text");
[843]43
[2821]44    cv = caca_create_canvas(caca_get_canvas_width(pig) * 2,
45                             caca_get_canvas_height(pig) * 2);
[843]46
[1753]47    if(cv == NULL || pig == NULL)
48    {
49        printf("Can't created canvas\n");
50        return -1;
51    }
52
[2821]53    caca_blit(cv, 0, 0, pig, NULL);
54    caca_flip(pig);
55    caca_blit(cv, caca_get_canvas_width(pig), 0, pig, NULL);
56    caca_flip(pig);
57    caca_flop(pig);
58    caca_blit(cv, 0, caca_get_canvas_height(pig), pig, NULL);
59    caca_flop(pig);
60    caca_rotate_180(pig);
61    caca_blit(cv, caca_get_canvas_width(pig),
62                   caca_get_canvas_height(pig), pig, NULL);
[1308]63
[2821]64    for(j = 0; j < caca_get_canvas_height(cv); j++)
[1808]65    {
[2821]66        for(i = 0; i < caca_get_canvas_width(cv); i += 2)
[1808]67        {
68            unsigned long int a;
[2821]69            caca_set_color_ansi(cv, CACA_LIGHTBLUE + (i + j) % 6,
70                                 CACA_DEFAULT);
71            a = caca_get_attr(cv, -1, -1);
72            caca_put_attr(cv, i, j, a);
73            caca_put_attr(cv, i + 1, j, a);
[1808]74        }
75    }
76
[3495]77    buffer = caca_export_canvas_to_memory(cv, "utf8", &len);
[1308]78    fwrite(buffer, len, 1, stdout);
79    free(buffer);
[843]80
[2821]81    caca_rotate_left(cv);
[3495]82    buffer = caca_export_canvas_to_memory(cv, "utf8", &len);
[1787]83    fwrite(buffer, len, 1, stdout);
84    free(buffer);
85
[2821]86    caca_free_canvas(pig);
87    caca_free_canvas(cv);
[843]88
89    return 0;
90}
91
Note: See TracBrowser for help on using the repository browser.