1 | /* |
---|
2 | * text canvas text import/export |
---|
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 | # include <stdlib.h> |
---|
19 | #endif |
---|
20 | |
---|
21 | #include "caca.h" |
---|
22 | |
---|
23 | #define STRING \ |
---|
24 | " |_| \n" \ |
---|
25 | " _,----._ | | \n" \ |
---|
26 | " (/ @ @ \\) __ \n" \ |
---|
27 | " | OO | |_ \n" \ |
---|
28 | " \\ `--' / |__ \n" \ |
---|
29 | " `----' \n" \ |
---|
30 | " |_| \n" \ |
---|
31 | " Hello world! | \n" \ |
---|
32 | " \n" |
---|
33 | |
---|
34 | int main(int argc, char *argv[]) |
---|
35 | { |
---|
36 | caca_canvas_t *cv, *pig; |
---|
37 | void *buffer; |
---|
38 | size_t len; |
---|
39 | int i, j; |
---|
40 | |
---|
41 | pig = caca_create_canvas(0, 0); |
---|
42 | caca_import_canvas_from_memory(pig, STRING, strlen(STRING), "text"); |
---|
43 | |
---|
44 | cv = caca_create_canvas(caca_get_canvas_width(pig) * 2, |
---|
45 | caca_get_canvas_height(pig) * 2); |
---|
46 | |
---|
47 | if(cv == NULL || pig == NULL) |
---|
48 | { |
---|
49 | printf("Can't created canvas\n"); |
---|
50 | return -1; |
---|
51 | } |
---|
52 | |
---|
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); |
---|
63 | |
---|
64 | for(j = 0; j < caca_get_canvas_height(cv); j++) |
---|
65 | { |
---|
66 | for(i = 0; i < caca_get_canvas_width(cv); i += 2) |
---|
67 | { |
---|
68 | unsigned long int a; |
---|
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); |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | buffer = caca_export_canvas_to_memory(cv, "utf8", &len); |
---|
78 | fwrite(buffer, len, 1, stdout); |
---|
79 | free(buffer); |
---|
80 | |
---|
81 | caca_rotate_left(cv); |
---|
82 | buffer = caca_export_canvas_to_memory(cv, "utf8", &len); |
---|
83 | fwrite(buffer, len, 1, stdout); |
---|
84 | free(buffer); |
---|
85 | |
---|
86 | caca_free_canvas(pig); |
---|
87 | caca_free_canvas(cv); |
---|
88 | |
---|
89 | return 0; |
---|
90 | } |
---|
91 | |
---|