Changeset 2255 for libcaca


Ignore:
Timestamp:
Mar 2, 2008, 5:28:10 PM (15 years ago)
Author:
Jean-Yves Lamoureux
Message:
  • Improved ellipse rendering. Not perfect, but still much better than

old method. Closes #16 .

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/cucul/conic.c

    r1462 r2255  
    2828#include "cucul_internals.h"
    2929
    30 static void ellipsepoints(cucul_canvas_t *, int, int, int, int, uint32_t);
     30static void ellipsepoints(cucul_canvas_t *, int, int, int, int, uint32_t, int);
    3131
    3232/** \brief Draw a circle on the canvas using the given character.
     
    4949    for(test = 0, dx = 0, dy = r ; dx <= dy ; dx++)
    5050    {
    51         ellipsepoints(cv, x, y, dx, dy, ch);
    52         ellipsepoints(cv, x, y, dy, dx, ch);
     51        ellipsepoints(cv, x, y, dx, dy, ch, 1);
     52        ellipsepoints(cv, x, y, dy, dx, ch, 1);
    5353
    5454        test += test > 0 ? dx - dy-- : dx;
     
    138138    int d1 = b*b - (a*a*b) + (a*a/4);
    139139
    140     ellipsepoints(cv, xo, yo, x, y, ch);
     140    ellipsepoints(cv, xo, yo, x, y, ch, 0);
    141141
    142142    while(a*a*y - a*a/2 > b*b*(x+1))
     
    152152        }
    153153        x++;
    154         ellipsepoints(cv, xo, yo, x, y, ch);
     154        ellipsepoints(cv, xo, yo, x, y, ch, 0);
    155155    }
    156156
     
    169169
    170170        y--;
    171         ellipsepoints(cv, xo, yo, x, y, ch);
     171        ellipsepoints(cv, xo, yo, x, y, ch, 0);
    172172    }
    173173
     
    194194    int d1 = b*b - (a*a*b) + (a*a/4);
    195195
    196     ellipsepoints(cv, xo, yo, x, y, '-');
     196    ellipsepoints(cv, xo, yo, x, y, '-', 1);
    197197
    198198    while(a*a*y - a*a/2 > b*b*(x+1))
     
    201201        {
    202202            d1 += b*b*(2*x+1); /* XXX: "Computer Graphics" has + 3 here. */
     203            ellipsepoints(cv, xo, yo, x + 1, y, '0', 1);
    203204        }
    204205        else
     
    206207            d1 += b*b*(2*x*1) + a*a*(-2*y+2);
    207208            y--;
     209            ellipsepoints(cv, xo, yo, x + 1, y, '1', 1);
    208210        }
    209211        x++;
    210         ellipsepoints(cv, xo, yo, x, y, '-');
     212       
     213       
    211214    }
    212215
     
    218221            d2 += b*b*(2*x+2) + a*a*(-2*y+3);
    219222            x++;
     223            ellipsepoints(cv, xo, yo, x , y - 1, '2', 1);
    220224        }
    221225        else
    222226        {
    223227            d2 += a*a*(-2*y+3);
     228            ellipsepoints(cv, xo, yo, x , y - 1, '3', 1);
    224229        }
    225230
    226231        y--;
    227         ellipsepoints(cv, xo, yo, x, y, '|');
     232       
     233       
    228234    }
    229235
     
    232238
    233239static void ellipsepoints(cucul_canvas_t *cv, int xo, int yo, int x, int y,
    234                           uint32_t ch)
     240                          uint32_t ch, int thin)
    235241{
    236242    uint8_t b = 0;
     
    245251        b |= 0x8;
    246252
    247     if((b & (0x1|0x4)) == (0x1|0x4))
    248         cucul_put_char(cv, xo + x, yo + y, ch);
    249 
    250     if((b & (0x2|0x4)) == (0x2|0x4))
    251         cucul_put_char(cv, xo - x, yo + y, ch);
    252 
    253     if((b & (0x1|0x8)) == (0x1|0x8))
    254         cucul_put_char(cv, xo + x, yo - y, ch);
    255 
    256     if((b & (0x2|0x8)) == (0x2|0x8))
    257         cucul_put_char(cv, xo - x, yo - y, ch);
    258 }
    259 
     253    if((b & (0x1|0x4)) == (0x1|0x4)) {
     254        char c = ch;
     255       
     256        if(thin) {
     257            switch(c) {
     258            case '0':
     259                c = '-';
     260                break;
     261            case '1':
     262                c = ',';
     263                break;
     264            case '2':
     265                c = '/';
     266                break;
     267            case '3':
     268                c = '|';
     269                break;
     270            }
     271
     272        }
     273        cucul_put_char(cv, xo + x, yo + y, c);
     274    }
     275    if((b & (0x2|0x4)) == (0x2|0x4)) {
     276        char c = ch;
     277       
     278        if(thin) {
     279            switch(c) {
     280            case '0':
     281                c = '-';
     282                break;
     283            case '1':
     284                c = '.';
     285                break;
     286            case '2':
     287                c = '\\';
     288                break;
     289            case '3':
     290                c = '|';
     291                break;
     292            }
     293
     294        }
     295        cucul_put_char(cv, xo - x, yo + y, c);
     296    }
     297
     298
     299    if((b & (0x1|0x8)) == (0x1|0x8)) {
     300        char c = ch;
     301       
     302        if(thin) {
     303            switch(c) {
     304            case '0':
     305                c = '-';
     306                break;
     307            case '1':
     308                c = '`';
     309                break;
     310            case '2':
     311                c = '\\';
     312                break;
     313            case '3':
     314                c = '|';
     315                break;
     316            }
     317
     318        }
     319        cucul_put_char(cv, xo + x, yo - y, c);
     320    }
     321
     322    if((b & (0x2|0x8)) == (0x2|0x8)) {
     323        char c = ch;
     324       
     325        if(thin) {
     326            switch(c) {
     327            case '0':
     328                c = '-';
     329                break;
     330            case '1':
     331                c = '\'';
     332                break;
     333            case '2':
     334                c = '/';
     335                break;
     336            case '3':
     337                c = '|';
     338                break;
     339            }
     340
     341        }
     342        cucul_put_char(cv, xo - x, yo - y, c);
     343    }
     344
     345       
     346}
     347
Note: See TracChangeset for help on using the changeset viewer.