source: libcaca/trunk/examples/frames.c @ 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:keywords set to Id
File size: 2.4 KB
Line 
1/*
2 *  frames        canvas frame switching features
3 *  Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
4 *                All Rights Reserved
5 *
6 *  $Id: frames.c 4148 2009-12-19 14:38:38Z sam $
7 *
8 *  This program is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15#include "config.h"
16
17#if !defined(__KERNEL__)
18#   include <stdio.h>
19#endif
20
21#include "caca.h"
22
23int main(int argc, char *argv[])
24{
25    caca_canvas_t *cv;
26    caca_display_t *dp;
27
28    int n, frame;
29
30    /* Create a canvas with 200 frames */
31    cv = caca_create_canvas(0, 0);
32    if(cv == NULL)
33    {
34        printf("Can't create canvas\n");
35        return -1;
36    }
37
38    for(frame = 1; frame < 200; frame++)
39        caca_create_frame(cv, frame);
40
41    fprintf(stderr, "canvas created, size is %ix%i\n",
42            caca_get_canvas_width(cv), caca_get_canvas_height(cv));
43
44    /* Resize it to 150 x 80 (around 19MB) */
45    caca_set_canvas_size(cv, 150, 80);
46
47    fprintf(stderr, "canvas expanded, size is %ix%i\n",
48            caca_get_canvas_width(cv), caca_get_canvas_height(cv));
49
50    /* Fill the first 16 frames with a different colour */
51    for(frame = 0; frame < 16; frame++)
52    {
53        caca_set_frame(cv, frame);
54        caca_set_color_ansi(cv, CACA_WHITE, frame);
55        caca_fill_box(cv, 0, 0, 40, 15, ':');
56        caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
57        caca_put_str(cv, frame * 5 / 2, frame, "カカ");
58        caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT);
59    }
60
61    /* Resize it to a more decent size */
62    caca_set_canvas_size(cv, 41, 16);
63
64    fprintf(stderr, "canvas shrinked, size is %ix%i\n",
65            caca_get_canvas_width(cv), caca_get_canvas_height(cv));
66
67    dp = caca_create_display(cv);
68    caca_set_display_time(dp, 50000);
69
70    fprintf(stderr, "display attached, size is %ix%i\n",
71            caca_get_canvas_width(cv), caca_get_canvas_height(cv));
72
73    n = 0;
74    while(!caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, 0))
75    {
76        caca_set_frame(cv, n % 16);
77        caca_refresh_display(dp);
78        n++;
79    }
80
81    caca_free_display(dp);
82
83    /* It is possible, though not necessary, to free all additional frames
84     * separately. */
85    caca_free_canvas(cv);
86
87    return 0;
88}
89
Note: See TracBrowser for help on using the repository browser.