~ubuntu-branches/ubuntu/gutsy/libcaca/gutsy

« back to all changes in this revision

Viewing changes to test/demo0.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hocevar (Debian packages)
  • Date: 2006-12-03 02:05:11 UTC
  • mfrom: (3.1.6 feisty)
  • Revision ID: james.westby@ubuntu.com-20061203020511-h5nzqgf8nov7ns3z
Tags: 0.99.beta11.debian-2
Remove toilet from caca-utils now that it has entered testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  demo          demo for libcaca version 0.9
 
3
 *  Copyright (c) 2003 Sam Hocevar <sam@zoy.org>
 
4
 *                All Rights Reserved
 
5
 *
 
6
 *  $Id: demo0.c 829 2006-09-17 12:44:18Z jylam $
 
7
 *
 
8
 *  This program is free software; you can redistribute it and/or
 
9
 *  modify it under the terms of the GNU Lesser General Public
 
10
 *  License as published by the Free Software Foundation; either
 
11
 *  version 2 of the License, or (at your option) any later version.
 
12
 *
 
13
 *  This program is distributed in the hope that it will be useful,
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 *  Lesser General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU Lesser General Public
 
19
 *  License along with this program; if not, write to the Free Software
 
20
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 
21
 *  02111-1307  USA
 
22
 */
 
23
 
 
24
#include "config.h"
 
25
 
 
26
#if !defined(__KERNEL__)
 
27
#   include <math.h>
 
28
#   include <string.h>
 
29
#   include <stdio.h>
 
30
#endif
 
31
 
 
32
#include "caca0.h"
 
33
 
 
34
static void display_menu(void);
 
35
 
 
36
static void demo_all(void);
 
37
 
 
38
static void demo_color(void);
 
39
static void demo_dots(void);
 
40
static void demo_lines(void);
 
41
static void demo_boxes(void);
 
42
static void demo_ellipses(void);
 
43
static void demo_triangles(void);
 
44
#if 0
 
45
static void demo_sprites(void);
 
46
#endif
 
47
static void demo_render(void);
 
48
 
 
49
int bounds = 0;
 
50
int outline = 0;
 
51
int dithering = 0;
 
52
struct caca_sprite *sprite = NULL;
 
53
 
 
54
int main(int argc, char **argv)
 
55
{
 
56
    void (*demo)(void) = NULL;
 
57
    int quit = 0;
 
58
 
 
59
    if(caca_init())
 
60
        return 1;
 
61
 
 
62
    caca_set_delay(40000);
 
63
 
 
64
    /* Initialize data */
 
65
#if 0
 
66
    sprite = caca_load_sprite(DATADIR "/caca.txt");
 
67
    if(!sprite)
 
68
        sprite = caca_load_sprite("caca.txt");
 
69
    if(!sprite)
 
70
        sprite = caca_load_sprite("examples/caca.txt");
 
71
#endif
 
72
 
 
73
    /* Main menu */
 
74
    display_menu();
 
75
 
 
76
    /* Go ! */
 
77
    while(!quit)
 
78
    {
 
79
        int menu = 0, mouse = 0, xmouse = 0, ymouse = 0;
 
80
        int event;
 
81
 
 
82
        while((event = caca_get_event(CACA_EVENT_ANY)))
 
83
        {
 
84
            if(demo && (event & CACA_EVENT_KEY_PRESS))
 
85
            {
 
86
                menu = 1;
 
87
                demo = NULL;
 
88
            }
 
89
            else if(event & CACA_EVENT_KEY_PRESS)
 
90
            {
 
91
                switch(event & 0xffff)
 
92
                {
 
93
                case 'q':
 
94
                case 'Q':
 
95
                    demo = NULL;
 
96
                    quit = 1;
 
97
                    break;
 
98
                case 'o':
 
99
                case 'O':
 
100
                    outline = (outline + 1) % 3;
 
101
                    display_menu();
 
102
                    break;
 
103
                case 'b':
 
104
                case 'B':
 
105
                    bounds = (bounds + 1) % 2;
 
106
                    display_menu();
 
107
                    break;
 
108
                case 'd':
 
109
                case 'D':
 
110
                    dithering = (dithering + 1) % 5;
 
111
                    caca_set_dithering(CACA_DITHERING_NONE + dithering);
 
112
                    display_menu();
 
113
                    break;
 
114
                case 'c':
 
115
                    demo = demo_color;
 
116
                    break;
 
117
                case 'f':
 
118
                case 'F':
 
119
                    demo = demo_all;
 
120
                    break;
 
121
                case '1':
 
122
                    demo = demo_dots;
 
123
                    break;
 
124
                case '2':
 
125
                    demo = demo_lines;
 
126
                    break;
 
127
                case '3':
 
128
                    demo = demo_boxes;
 
129
                    break;
 
130
                case '4':
 
131
                    demo = demo_triangles;
 
132
                    break;
 
133
                case '5':
 
134
                    demo = demo_ellipses;
 
135
                    break;
 
136
#if 0
 
137
                case 's':
 
138
                case 'S':
 
139
                    if(sprite)
 
140
                        demo = demo_sprites;
 
141
                    break;
 
142
#endif
 
143
                case 'r':
 
144
                case 'R':
 
145
                    demo = demo_render;
 
146
                    break;
 
147
                }
 
148
 
 
149
                if(demo)
 
150
                    caca_clear();
 
151
            }
 
152
            else if(event & CACA_EVENT_MOUSE_MOTION)
 
153
            {
 
154
                mouse = 1;
 
155
                xmouse = (event & 0xfff000) >> 12;
 
156
                ymouse = event & 0xfff;
 
157
            }
 
158
        }
 
159
 
 
160
        if(menu || (mouse && !demo))
 
161
        {
 
162
            display_menu();
 
163
            if(mouse && !demo)
 
164
            {
 
165
                caca_set_color(CACA_COLOR_RED, CACA_COLOR_BLACK);
 
166
                caca_putstr(xmouse, ymouse, "|\\");
 
167
            }
 
168
            caca_refresh();
 
169
            mouse = menu = 0;
 
170
        }
 
171
 
 
172
        if(demo)
 
173
        {
 
174
            demo();
 
175
 
 
176
            caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK);
 
177
            caca_draw_thin_box(1, 1, caca_get_width() - 2, caca_get_height() - 2);
 
178
            caca_printf(4, 1, "[%i.%i fps]----",
 
179
                            1000000 / caca_get_rendertime(),
 
180
                            (10000000 / caca_get_rendertime()) % 10);
 
181
            caca_refresh();
 
182
        }
 
183
    }
 
184
 
 
185
    /* Clean up */
 
186
#if 0
 
187
    caca_free_sprite(sprite);
 
188
#endif
 
189
    caca_end();
 
190
 
 
191
    return 0;
 
192
}
 
193
 
 
194
static void display_menu(void)
 
195
{
 
196
    int xo = caca_get_width() - 2;
 
197
    int yo = caca_get_height() - 2;
 
198
 
 
199
    caca_clear();
 
200
    caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK);
 
201
    caca_draw_thin_box(1, 1, xo, yo);
 
202
 
 
203
    caca_putstr((xo - strlen("libcaca demo")) / 2, 3, "libcaca demo");
 
204
    caca_putstr((xo - strlen("==============")) / 2, 4, "==============");
 
205
 
 
206
    caca_putstr(4, 6, "demos:");
 
207
    caca_putstr(4, 7, "'f': full");
 
208
    caca_putstr(4, 8, "'1': dots");
 
209
    caca_putstr(4, 9, "'2': lines");
 
210
    caca_putstr(4, 10, "'3': boxes");
 
211
    caca_putstr(4, 11, "'4': triangles");
 
212
    caca_putstr(4, 12, "'5': ellipses");
 
213
    caca_putstr(4, 13, "'c': colour");
 
214
    caca_putstr(4, 14, "'r': render");
 
215
    if(sprite)
 
216
        caca_putstr(4, 15, "'s': sprites");
 
217
 
 
218
    caca_putstr(4, 16, "settings:");
 
219
    caca_printf(4, 17, "'o': outline: %s",
 
220
              outline == 0 ? "none" : outline == 1 ? "solid" : "thin");
 
221
    caca_printf(4, 18, "'b': drawing boundaries: %s",
 
222
              bounds == 0 ? "screen" : "infinite");
 
223
    caca_printf(4, 19, "'d': dithering (%s)",
 
224
                caca_get_dithering_name(CACA_DITHERING_NONE + dithering));
 
225
 
 
226
    caca_putstr(4, yo - 2, "'q': quit");
 
227
    caca_refresh();
 
228
}
 
229
 
 
230
static void demo_all(void)
 
231
{
 
232
    static int i = 0;
 
233
 
 
234
    int j, xo, yo, xa, ya, xb, yb, xc, yc;
 
235
 
 
236
    i++;
 
237
 
 
238
    caca_clear();
 
239
 
 
240
    /* Draw the sun */
 
241
    caca_set_color(CACA_COLOR_YELLOW, CACA_COLOR_BLACK);
 
242
    xo = caca_get_width() / 4;
 
243
    yo = caca_get_height() / 4 + 5 * sin(0.03*i);
 
244
 
 
245
    for(j = 0; j < 16; j++)
 
246
    {
 
247
        xa = xo - (30 + sin(0.03*i) * 8) * sin(0.03*i + M_PI*j/8);
 
248
        ya = yo + (15 + sin(0.03*i) * 4) * cos(0.03*i + M_PI*j/8);
 
249
        caca_draw_thin_line(xo, yo, xa, ya);
 
250
    }
 
251
 
 
252
    j = 15 + sin(0.03*i) * 8;
 
253
    caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK);
 
254
    caca_fill_ellipse(xo, yo, j, j / 2, '#');
 
255
    caca_set_color(CACA_COLOR_YELLOW, CACA_COLOR_BLACK);
 
256
    caca_draw_ellipse(xo, yo, j, j / 2, '#');
 
257
 
 
258
    /* Draw the pyramid */
 
259
    xo = caca_get_width() * 5 / 8;
 
260
    yo = 2;
 
261
 
 
262
    xa = caca_get_width() / 8 + sin(0.03*i) * 5;
 
263
    ya = caca_get_height() / 2 + cos(0.03*i) * 5;
 
264
 
 
265
    xb = caca_get_width() - 10 - cos(0.02*i) * 10;
 
266
    yb = caca_get_height() * 3 / 4 - 5 + sin(0.02*i) * 5;
 
267
 
 
268
    xc = caca_get_width() / 4 - sin(0.02*i) * 5;
 
269
    yc = caca_get_height() * 3 / 4 + cos(0.02*i) * 5;
 
270
 
 
271
    caca_set_color(CACA_COLOR_GREEN, CACA_COLOR_BLACK);
 
272
    caca_fill_triangle(xo, yo, xb, yb, xa, ya, '%');
 
273
    caca_set_color(CACA_COLOR_YELLOW, CACA_COLOR_BLACK);
 
274
    caca_draw_thin_triangle(xo, yo, xb, yb, xa, ya);
 
275
 
 
276
    caca_set_color(CACA_COLOR_RED, CACA_COLOR_BLACK);
 
277
    caca_fill_triangle(xa, ya, xb, yb, xc, yc, '#');
 
278
    caca_set_color(CACA_COLOR_YELLOW, CACA_COLOR_BLACK);
 
279
    caca_draw_thin_triangle(xa, ya, xb, yb, xc, yc);
 
280
 
 
281
    caca_set_color(CACA_COLOR_BLUE, CACA_COLOR_BLACK);
 
282
    caca_fill_triangle(xo, yo, xb, yb, xc, yc, '%');
 
283
    caca_set_color(CACA_COLOR_YELLOW, CACA_COLOR_BLACK);
 
284
    caca_draw_thin_triangle(xo, yo, xb, yb, xc, yc);
 
285
 
 
286
    /* Draw a background triangle */
 
287
    xa = 2;
 
288
    ya = 2;
 
289
 
 
290
    xb = caca_get_width() - 3;
 
291
    yb = caca_get_height() / 2;
 
292
 
 
293
    xc = caca_get_width() / 3;
 
294
    yc = caca_get_height() - 3;
 
295
 
 
296
    caca_set_color(CACA_COLOR_CYAN, CACA_COLOR_BLACK);
 
297
    caca_draw_thin_triangle(xa, ya, xb, yb, xc, yc);
 
298
 
 
299
    xo = caca_get_width() / 2 + cos(0.027*i) * caca_get_width() / 3;
 
300
    yo = caca_get_height() / 2 - sin(0.027*i) * caca_get_height() / 2;
 
301
 
 
302
    caca_draw_thin_line(xa, ya, xo, yo);
 
303
    caca_draw_thin_line(xb, yb, xo, yo);
 
304
    caca_draw_thin_line(xc, yc, xo, yo);
 
305
 
 
306
    /* Draw a sprite on the pyramid */
 
307
#if 0
 
308
    caca_draw_sprite(xo, yo, sprite, 0);
 
309
#endif
 
310
 
 
311
    /* Draw a trail behind the foreground sprite */
 
312
    for(j = i - 60; j < i; j++)
 
313
    {
 
314
        int delta = caca_rand(-5, 5);
 
315
        caca_set_color(caca_rand(0, 15), caca_rand(0, 15));
 
316
        caca_putchar(caca_get_width() / 2
 
317
                    + cos(0.02*j) * (delta + caca_get_width() / 4),
 
318
                   caca_get_height() / 2
 
319
                    + sin(0.02*j) * (delta + caca_get_height() / 3),
 
320
                   '#');
 
321
    }
 
322
 
 
323
    /* Draw foreground sprite */
 
324
#if 0
 
325
    caca_draw_sprite(caca_get_width() / 2 + cos(0.02*i) * caca_get_width() / 4,
 
326
                   caca_get_height() / 2 + sin(0.02*i) * caca_get_height() / 3,
 
327
                   sprite, 0);
 
328
#endif
 
329
}
 
330
 
 
331
static void demo_dots(void)
 
332
{
 
333
    int xmax = caca_get_width() - 1;
 
334
    int ymax = caca_get_height() - 1;
 
335
    int i;
 
336
    static char chars[10] =
 
337
    {
 
338
        '+', '-', '*', '#', 'X', '@', '%', '$', 'M', 'W'
 
339
    };
 
340
 
 
341
    for(i = 1000; i--;)
 
342
    {
 
343
        /* Putpixel */
 
344
        caca_set_color(caca_rand(0, 15), caca_rand(0, 15));
 
345
        caca_putchar(caca_rand(0, xmax), caca_rand(0, ymax),
 
346
                     chars[caca_rand(0, 9)]);
 
347
    }
 
348
}
 
349
 
 
350
static void demo_color(void)
 
351
{
 
352
    int i, j;
 
353
    char buf[BUFSIZ];
 
354
 
 
355
    caca_clear();
 
356
    for(i = 0; i < 16; i++)
 
357
    {
 
358
        sprintf(buf, "'%c': %i (%s)", 'a' + i, i, caca_get_color_name(i));
 
359
        caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK);
 
360
        caca_putstr(4, i + (i >= 8 ? 4 : 3), buf);
 
361
        for(j = 0; j < 16; j++)
 
362
        {
 
363
            caca_set_color(i, j);
 
364
            caca_putstr((j >= 8 ? 41 : 40) + j * 2, i + (i >= 8 ? 4 : 3), "# ");
 
365
        }
 
366
    }
 
367
}
 
368
 
 
369
static void demo_lines(void)
 
370
{
 
371
    int w = caca_get_width();
 
372
    int h = caca_get_height();
 
373
    int xa, ya, xb, yb;
 
374
 
 
375
    if(bounds)
 
376
    {
 
377
        xa = caca_rand(- w, 2 * w); ya = caca_rand(- h, 2 * h);
 
378
        xb = caca_rand(- w, 2 * w); yb = caca_rand(- h, 2 * h);
 
379
    }
 
380
    else
 
381
    {
 
382
        xa = caca_rand(0, w - 1); ya = caca_rand(0, h - 1);
 
383
        xb = caca_rand(0, w - 1); yb = caca_rand(0, h - 1);
 
384
    }
 
385
 
 
386
    caca_set_color(caca_rand(0, 15), CACA_COLOR_BLACK);
 
387
    if(outline > 1)
 
388
        caca_draw_thin_line(xa, ya, xb, yb);
 
389
    else
 
390
        caca_draw_line(xa, ya, xb, yb, '#');
 
391
}
 
392
 
 
393
static void demo_boxes(void)
 
394
{
 
395
    int w = caca_get_width();
 
396
    int h = caca_get_height();
 
397
    int xa, ya, xb, yb;
 
398
 
 
399
    if(bounds)
 
400
    {
 
401
        xa = caca_rand(- w, 2 * w); ya = caca_rand(- h, 2 * h);
 
402
        xb = caca_rand(- w, 2 * w); yb = caca_rand(- h, 2 * h);
 
403
    }
 
404
    else
 
405
    {
 
406
        xa = caca_rand(0, w - 1); ya = caca_rand(0, h - 1);
 
407
        xb = caca_rand(0, w - 1); yb = caca_rand(0, h - 1);
 
408
    }
 
409
 
 
410
    caca_set_color(caca_rand(0, 15), caca_rand(0, 15));
 
411
    caca_fill_box(xa, ya, xb, yb, '#');
 
412
 
 
413
    caca_set_color(caca_rand(0, 15), CACA_COLOR_BLACK);
 
414
    if(outline == 2)
 
415
        caca_draw_thin_box(xa, ya, xb, yb);
 
416
    else if(outline == 1)
 
417
        caca_draw_box(xa, ya, xb, yb, '#');
 
418
}
 
419
 
 
420
static void demo_ellipses(void)
 
421
{
 
422
    int w = caca_get_width();
 
423
    int h = caca_get_height();
 
424
    int x, y, a, b;
 
425
 
 
426
    if(bounds)
 
427
    {
 
428
        x = caca_rand(- w, 2 * w); y = caca_rand(- h, 2 * h);
 
429
        a = caca_rand(0, w); b = caca_rand(0, h);
 
430
    }
 
431
    else
 
432
    {
 
433
        do
 
434
        {
 
435
            x = caca_rand(0, w); y = caca_rand(0, h);
 
436
            a = caca_rand(0, w); b = caca_rand(0, h);
 
437
 
 
438
        } while(x - a < 0 || x + a >= w || y - b < 0 || y + b >= h);
 
439
    }
 
440
 
 
441
    caca_set_color(caca_rand(0, 15), caca_rand(0, 15));
 
442
    caca_fill_ellipse(x, y, a, b, '#');
 
443
 
 
444
    caca_set_color(caca_rand(0, 15), CACA_COLOR_BLACK);
 
445
    if(outline == 2)
 
446
        caca_draw_thin_ellipse(x, y, a, b);
 
447
    else if(outline == 1)
 
448
        caca_draw_ellipse(x, y, a, b, '#');
 
449
}
 
450
 
 
451
static void demo_triangles(void)
 
452
{
 
453
    int w = caca_get_width();
 
454
    int h = caca_get_height();
 
455
    int xa, ya, xb, yb, xc, yc;
 
456
 
 
457
    if(bounds)
 
458
    {
 
459
        xa = caca_rand(- w, 2 * w); ya = caca_rand(- h, 2 * h);
 
460
        xb = caca_rand(- w, 2 * w); yb = caca_rand(- h, 2 * h);
 
461
        xc = caca_rand(- w, 2 * w); yc = caca_rand(- h, 2 * h);
 
462
    }
 
463
    else
 
464
    {
 
465
 
 
466
        xa = caca_rand(0, w - 1); ya = caca_rand(0, h - 1);
 
467
        xb = caca_rand(0, w - 1); yb = caca_rand(0, h - 1);
 
468
        xc = caca_rand(0, w - 1); yc = caca_rand(0, h - 1);
 
469
    }
 
470
 
 
471
    caca_set_color(caca_rand(0, 15), caca_rand(0, 15));
 
472
    caca_fill_triangle(xa, ya, xb, yb, xc, yc, '#');
 
473
 
 
474
    caca_set_color(caca_rand(0, 15), CACA_COLOR_BLACK);
 
475
    if(outline == 2)
 
476
        caca_draw_thin_triangle(xa, ya, xb, yb, xc, yc);
 
477
    else if(outline == 1)
 
478
        caca_draw_triangle(xa, ya, xb, yb, xc, yc, '#');
 
479
}
 
480
 
 
481
#if 0
 
482
static void demo_sprites(void)
 
483
{
 
484
    caca_draw_sprite(caca_rand(0, caca_get_width() - 1),
 
485
                   caca_rand(0, caca_get_height() - 1), sprite, 0);
 
486
}
 
487
#endif
 
488
 
 
489
#if 0
 
490
static void demo_render(void)
 
491
{
 
492
    struct caca_bitmap *bitmap;
 
493
    //short buffer[256*256];
 
494
    //short *dest = buffer;
 
495
    int buffer[256*256];
 
496
    int *dest = buffer;
 
497
    int x, y, z;
 
498
    static int i = 0;
 
499
 
 
500
    i = (i + 1) % 512;
 
501
    z = i < 256 ? i : 511 - i;
 
502
 
 
503
    for(x = 0; x < 256; x++)
 
504
        for(y = 0; y < 256; y++)
 
505
    {
 
506
        //*dest++ = ((x >> 3) << 11) | ((y >> 2) << 5) | ((z >> 3));
 
507
        *dest++ = (x << 16) | (y << 8) | (z);
 
508
    }
 
509
 
 
510
    //bitmap = caca_create_bitmap(16, 256, 256, 2 * 256, 0xf800, 0x07e0, 0x001f, 0x0000);
 
511
    bitmap = caca_create_bitmap(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
 
512
    caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1,
 
513
                     bitmap, buffer);
 
514
    caca_free_bitmap(bitmap);
 
515
}
 
516
#endif
 
517
 
 
518
static void draw_circle(int *buffer, int xo, int yo, int r, int mask, int val);
 
519
 
 
520
static void demo_render(void)
 
521
{
 
522
    struct caca_bitmap *bitmap;
 
523
    int buffer[256*256];
 
524
    int *dest;
 
525
    int x, y, z, xo, yo;
 
526
    static int i = 0;
 
527
 
 
528
    i++;
 
529
 
 
530
    dest = buffer;
 
531
    for(x = 0; x < 256; x++)
 
532
        for(y = 0; y < 256; y++)
 
533
    {
 
534
        *dest++ = 0xff000000;
 
535
    }
 
536
 
 
537
    /* red */
 
538
    xo = 128 + 48 * sin(0.02 * i);
 
539
    yo = 128 + 48 * cos(0.03 * i);
 
540
    for(z = 0; z < 240; z++)
 
541
        draw_circle(buffer, xo, yo, z, 0x00ff0000, 200 << 16);
 
542
 
 
543
    /* green */
 
544
    xo = 128 + 48 * sin(2 + 0.06 * i);
 
545
    yo = 128 + 48 * cos(2 + 0.05 * i);
 
546
    for(z = 0; z < 240; z++)
 
547
        draw_circle(buffer, xo, yo, z, 0x0000ff00, 200 << 8);
 
548
 
 
549
    /* blue */
 
550
    xo = 128 + 48 * sin(1 + 0.04 * i);
 
551
    yo = 128 + 48 * cos(1 + 0.03 * i);
 
552
    for(z = 0; z < 240; z++)
 
553
        draw_circle(buffer, xo, yo, z, 0x000000ff, 200);
 
554
 
 
555
    bitmap = caca_create_bitmap(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
 
556
    caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1,
 
557
                     bitmap, (char *)buffer);
 
558
    caca_free_bitmap(bitmap);
 
559
}
 
560
 
 
561
static void draw_circle(int *buffer, int x, int y, int r, int mask, int val)
 
562
{
 
563
    int t, dx, dy;
 
564
 
 
565
#define POINT(X,Y) \
 
566
    buffer[(X) + 256 * (Y)] = 0xff000000 | (buffer[(X) + 256 * (Y)] & ~mask) | val;
 
567
 
 
568
    for(t = 0, dx = 0, dy = r; dx <= dy; dx++)
 
569
    {
 
570
        POINT(x - dx / 3, y - dy / 3);
 
571
        POINT(x + dx / 3, y - dy / 3);
 
572
        POINT(x - dx / 3, y + dy / 3);
 
573
        POINT(x + dx / 3, y + dy / 3);
 
574
 
 
575
        POINT(x - dy / 3, y - dx / 3);
 
576
        POINT(x + dy / 3, y - dx / 3);
 
577
        POINT(x - dy / 3, y + dx / 3);
 
578
        POINT(x + dy / 3, y + dx / 3);
 
579
 
 
580
        t += t > 0 ? dx - dy-- : dx;
 
581
    }
 
582
}
 
583