Forum Casio - Autres questions


Index du Forum » Autres questions » [fx-CG 20] Liste des meilleures fonctions
LancelotHors ligneMembrePoints: 1274 Défis: 160 Message

[fx-CG 20] Liste des meilleures fonctions

Posté le 05/10/2013 18:41


Bonjour à tous et à toutes (oui, je pense qu'il n'y a pas que des hommes sur PC )

Afin de faciliter et d'encourager le travaille du programmeur en C, C++ sur fx-CG 20, j'ai décider d'ouvrir ce topic pour poster les meilleurs fonctions (affichage d'une image, Getkey, ...) que vous trouvez utile pour programmer. ce topic a comme but de faciliter la découverte de ces fonctions pour les nouveaux programmeurs (comme moi ) mais aussi permettre au expérimenté de faire part de leurs meilleurs fonctions qu'il ont crées ou utilisent

En voici celles qui me sont arrivées:
Getkey
Getkey
Le .c
int keydown(int basic_keycode)
{
    const unsigned short* keyboard_register = (unsigned short*)0xA44B0000;
    [purple]int[/purple] row, col, word, bit;
    row = basic_keycode%10;
    col = basic_keycode/10-1;
    word = row>>1;
    bit = col + 8*(row&1);
    [b][blue]return[/blue][/b] (0 != (keyboard_register[word] & 1<<bit));
}


Le .h
[brown]#ifndef _KEY[/brown]
[brown]#define _KEY[/brown]

[purple]int[/purple] key_down(int basic_keycode);

[b][green]/***************/
/** Key codes **/
/***************/[/green][/b]
[brown]#define K_F1    79[/brown]
[brown]#define K_F2    69[/brown]
[brown]#define K_F3    59[/brown]
[brown]#define K_F4    49[/brown]
[brown]#define K_F5    39[/brown]
[brown]#define K_F6    29[/brown]

[brown]#define K_SHIFT 78[/brown]
[brown]#define K_OPTN  68[/brown]
[brown]#define K_VARS  58[/brown]
[brown]#define K_MENU  48[/brown]
[brown]#define K_LEFT  38[/brown]
[brown]#define K_UP    28[/brown]

[brown]#define K_ALPHA 77[/brown]
[brown]#define K_SQR   67[/brown]
[brown]#define K_EXPO  57[/brown]
[brown]#define K_EXIT  47[/brown]
[brown]#define K_DOWN  37[/brown]
[brown]#define K_RIGHT 27[/brown]

[brown]#define K_THETA 76[/brown]
[brown]#define K_LOG   66[/brown]
[brown]#define K_LN    56[/brown]
[brown]#define K_SIN   46[/brown]
[brown]#define K_COS   36[/brown]
[brown]#define K_TAN   26[/brown]

[brown]#define K_FRAC  75[/brown]
[brown]#define K_FD    65[/brown]
[brown]#define K_LPAR  55[/brown]
[brown]#define K_RPAR  45[/brown]
[brown]#define K_COMMA 35[/brown]
[brown]#define K_STORE 25[/brown]

[brown]#define K_7     74[/brown]
[brown]#define K_8     64[/brown]
[brown]#define K_9     54[/brown]
[brown]#define K_DEL   34[/brown]

[brown]#define K_4     73[/brown]
[brown]#define K_5     63[/brown]
[brown]#define K_6     53[/brown]
[brown]#define K_MULT  43[/brown]
[brown]#define K_DIV   33[/brown]

[brown]#define K_1     72[/brown]
[brown]#define K_2     62[/brown]
[brown]#define K_3     52[/brown]
[brown]#define K_PLUS  42[/brown]
[brown]#define K_MINUS 32[/brown]

[brown]#define K_0     71[/brown]
[brown]#define K_DOT   61[/brown]
[brown]#define K_EXP   51[/brown]
[brown]#define K_NEG   41[/brown]
[brown]#define K_EXE   31[/brown]

[brown]#define K_AC    10[/brown]

#endif [green]//_KEY[/green]




Afficher un pixel
Afficher un pixel
void point(int x, int y, int color)
{
    char* VRAM = (char*)0xA8000000;
    VRAM += 2*(y*LCD_WIDTH_PX + x);
    *(VRAM++) = (color&0x0000FF00)>>8;
    *(VRAM++) = (color&0x000000FF);
    return;
}

Afficher un pixel avec la transparence
Afficher un pixel avec la transparence
static void text_drawPoint(int x, [purple]int[/purple] y, [purple]int[/purple] size, [purple]int[/purple] color, [purple]int[/purple] alpha)
{
    [purple]int[/purple] i, j;
    short* vram = VRAM;
    [b][blue]if[/blue][/b](x+size>=LCD_WIDTH_PX || x<0 || y+size>=LCD_HEIGHT_PX || y<0) [b][blue]return[/blue][/b];
    vram += y*LCD_WIDTH_PX + x;
    [b][blue]if[/blue][/b](alpha == [maroon]32[/maroon]) {
        [b][blue]for[/blue][/b](i=size ; i ; i--, vram+=LCD_WIDTH_PX-size) {
            [b][blue]for[/blue][/b](j=size ; j ; j--) {
                *(vram++) = color;
            }
        }
    } [b][blue]else[/blue][/b] {
        [b][blue]for[/blue][/b](i=size ; i ; i--, vram+=LCD_WIDTH_PX-size) {
            [b][blue]for[/blue][/b](j=size ; j ; j--) {
                *(vram++) = ((((color & 0xf81f) * alpha + (*vram & 0xf81f) * (32-alpha)) >> 5) & 0xf81f) |
                            ((((color & 0x07e0) * alpha + (*vram & 0x07e0) * (32-alpha)) >> 5) & 0x07e0);
            }
        }
    }
}

Valeur d'un pixel
Valeur d'un pixel
short CL_Getpixel(short x, short y)
{
     short *VRAM = GetVRAMAdress();
     [b][blue]return[/blue][/b] *(VRAM + (y * LCD_WIDTH_PX) + x);
}

Afficher une ligne
Afficher une ligne
void line(int x1, [purple]int[/purple] y1, [purple]int[/purple] x2, [purple]int[/purple] y2, short color)
{
    [purple]int[/purple] i, x, y, dx, dy, sx, sy, cumul;
    x = x1;
    y = y1;
    dx = x2 - x1;
    dy = y2 - y1;
    sx = sgn(dx);
    sy = sgn(dy);
    dx = abs(dx);
    dy = abs(dy);
    Bdisp_SetPoint_VRAM( x,  y,(int)  color );
    [b][blue]if[/blue][/b](dx > dy)
    {
        cumul = dx / 2;
        [b][blue]for[/blue][/b](i=[maroon]1[/maroon] ; i<dx ; i++)
        {
            x += sx;
            cumul += dy;
            [b][blue]if[/blue][/b](cumul > dx)
            {
                cumul -= dx;
                y += sy;
            }
            Bdisp_SetPoint_VRAM( x, y,(int)  color );
        }
    }
    [b][blue]else[/blue][/b]
    {
        cumul = dy / 2;
        [b][blue]for[/blue][/b](i=[maroon]1[/maroon] ; i<dy ; i++)
        {
            y += sy;
            cumul += dx;
            [b][blue]if[/blue][/b](cumul > dy)
            {
                cumul -= dy;
                x += sx;
            }
            Bdisp_SetPoint_VRAM(x, y,(int) color);
        }
    }
}

Tracer un cercle
Tracer un cercle
void drawCircle(int x0, [purple]int[/purple] y0, [purple]int[/purple] rayon, [purple]int[/purple] couleur)
{
   [purple]int[/purple] er = [maroon]1[/maroon] - rayon;
   [purple]int[/purple] erY = [maroon]1[/maroon];
   [purple]int[/purple] erX = -2 * rayon;
   [purple]int[/purple] x = rayon, y = [maroon]0[/maroon];

   point(x0, y0 + rayon, couleur);
   point(x0, y0 - rayon, couleur);
   point(x0 + rayon, y0, couleur);
   point(x0 - rayon, y0, couleur);

   [b][blue]while[/blue][/b](y < x)
   {
     [b][blue]if[/blue][/b](er > 0)
     {
       x--;
       erX += [maroon]2[/maroon];
       er += erX;
     }
     y++;
     erY += [maroon]2[/maroon];
     er += erY;    
     point(x0 + x, y0 + y, couleur);
     point(x0 - x, y0 + y, couleur);
     point(x0 + x, y0 - y, couleur);
     point(x0 - x, y0 - y, couleur);
     point(x0 + y, y0 + x, couleur);
     point(x0 - y, y0 + x, couleur);
     point(x0 + y, y0 - x, couleur);
     point(x0 - y, y0 - x, couleur);
   }
}

dessiner un cercle avec la transparence
dessiner un cercle avec la transparence

[brown]#define VRAM 0xA8000000[/brown]

void drawCircleAlpha(int x0, [purple]int[/purple] y0, [purple]int[/purple] rayon, [purple]int[/purple] couleur, [purple]int[/purple] alpha)
{
   [purple]int[/purple] er = [maroon]1[/maroon] - rayon;
   [purple]int[/purple] erY = [maroon]1[/maroon];
   [purple]int[/purple] erX = -2 * rayon;
   [purple]int[/purple] x = rayon, y = [maroon]0[/maroon];

   drawPoint(x0, y0 + rayon, [maroon]1[/maroon], couleur, alpha);
   drawPoint(x0, y0 - rayon, [maroon]1[/maroon], couleur, alpha);
   drawPoint(x0 + rayon, y0, [maroon]1[/maroon], couleur, alpha);
   drawPoint(x0 - rayon, y0, [maroon]1[/maroon], couleur, alpha);

   [b][blue]while[/blue][/b](y < x)
   {
     [b][blue]if[/blue][/b](error > 0)
     {
       x--;
       erX += [maroon]2[/maroon];
       er += erX;
     }
     y++;
     erY += [maroon]2[/maroon];
     er += erY;    
     drawPoint(x0 + x, y0 + y, [maroon]1[/maroon], couleur, alpha);
     drawPoint(x0 - x, y0 + y, [maroon]1[/maroon], couleur, alpha);
     drawPoint(x0 + x, y0 - y, [maroon]1[/maroon], couleur, alpha);
     drawPoint(x0 - x, y0 - y, [maroon]1[/maroon], couleur, alpha);
     drawPoint(x0 + y, y0 + x, [maroon]1[/maroon], couleur, alpha);
     drawPoint(x0 - y, y0 + x, [maroon]1[/maroon], couleur, alpha);
     drawPoint(x0 + y, y0 - x, [maroon]1[/maroon], couleur, alpha);
     drawPoint(x0 - y, y0 - x, [maroon]1[/maroon], couleur, alpha);
   }
}

static void drawPoint(int x, [purple]int[/purple] y, [purple]int[/purple] size, [purple]int[/purple] color, [purple]int[/purple] alpha)
{
     [purple]int[/purple] i, j;
     short* vram = VRAM;
     [b][blue]if[/blue][/b](x+size>=LCD_WIDTH_PX || x<0 || y+size>=LCD_HEIGHT_PX || y<0) [b][blue]return[/blue][/b];
     vram += y*LCD_WIDTH_PX + x;
     [b][blue]if[/blue][/b](alpha == [maroon]32[/maroon]) {
         [b][blue]for[/blue][/b](i=size ; i ; i--, vram+=LCD_WIDTH_PX-size) {
             [b][blue]for[/blue][/b](j=size ; j ; j--) {
                 *(vram++) = color;
             }
         }
     } [b][blue]else[/blue][/b] {
         [b][blue]for[/blue][/b](i=size ; i ; i--, vram+=LCD_WIDTH_PX-size) {
             [b][blue]for[/blue][/b](j=size ; j ; j--) {
                 *(vram++) = ((((color & 0xf81f) * alpha + (*vram & 0xf81f) * (32-alpha)) >> 5) & 0xf81f) |
                             ((((color & 0x07e0) * alpha + (*vram & 0x07e0) * (32-alpha)) >> 5) & 0x07e0);
             }
         }
     }
}


Tracer un disque
Tracer un disque
void CL_drawDiscus(int x0, [purple]int[/purple] y0, [purple]int[/purple] rayon, [purple]int[/purple] couleur)
{
     [purple]int[/purple] k;
     [purple]int[/purple] x,y,d;
     [b][blue]for[/blue][/b] (k=[maroon]0[/maroon]; k <= rayon; k++)
     {
         x = [maroon]0[/maroon];
         y = k;
         d = k - 1;
         [b][blue]while[/blue][/b] (y >= x)
         {
             CL_point( x0 + x, y0 + y, couleur);
             CL_point( x0 + y, y0 + x, couleur);
             CL_point( x0 - x, y0 + y, couleur);
             CL_point( x0 - y, y0 + x, couleur);
             CL_point( x0 + x, y0 - y, couleur);
             CL_point( x0 + y, y0 - x, couleur);
             CL_point( x0 - x, y0 - y, couleur);
             CL_point( x0 - y, y0 - x, couleur);
             [b][blue]if[/blue][/b] (d >= [maroon]2[/maroon]*x)
             {          
                 d -=[maroon]2[/maroon]*x+1;
                 x++;
             }
             [b][blue]else[/blue][/b] if (d < 2*(k-y))
             {
                 d += [maroon]2[/maroon]*y-1;
                 y--;
             }
             [b][blue]else[/blue][/b]
             {
                 d += [maroon]2[/maroon]*(y-x-1);
                 y--;
                 x++;
             }
         }
     }
}

Tracer un rectangle rempli
Tracer un rectangle rempli
void CL_Filled_Rectangle( [purple]int[/purple] xi, [purple]int[/purple] yi, [purple]int[/purple] xi2, [purple]int[/purple] yi2, unsigned short color)
{
         unsigned short* VRAM = GetVRAMAdress();
         [purple]int[/purple] i,j;
         const [purple]int[/purple] x = max(0,min(xi,xi2));
         const [purple]int[/purple] x2 = min( LCD_WIDTH_PX,max(xi,xi2));
        
         const [purple]int[/purple] y = max(0,min(yi,yi2));
         const [purple]int[/purple] y2 = min( LCD_WIDTH_PX,max(yi,yi2));
        
         const [purple]int[/purple] xm = max(x,x2);
         const [purple]int[/purple] ym = max(y,y2);
        
         const [purple]int[/purple] xe = x2-x+1;
        
         VRAM += LCD_WIDTH_PX*y + x;
         [b][blue]for[/blue][/b](j = min(y,y2); j <= ym; j++) {
                 [b][blue]for[/blue][/b](i=min(x,x2); i <= xm; i++) {
                         *(VRAM++) = color;
                 }
                 VRAM += LCD_WIDTH_PX-xe;
         }
}

tracer un polygone
tracer un polygone
void drawPoly(int xy[], int points, int color)
{
     int i;
     [b][blue]for[/blue][/b](i = [maroon]0[/maroon]; i < (points*2); i+=[maroon]2[/maroon])
     {
         [b][blue]if[/blue][/b](i < (points*2)-4)
         {
             line(xy[i ], xy[i+1], xy[i+2], xy[i+3], color);
         } [b][blue]else[/blue][/b]
         {
             line(xy[i ], xy[i+1], xy[0], xy[1], color);
         }
     }
}

Tracer un polygone rempli
Tracer un polygone rempli
static [purple]int[/purple] Filled_polygon_quicksord_partition(int *t, [purple]int[/purple] p, [purple]int[/purple] r) [green]//from MonochromeLib by PierrotLL[/green]
{
     [purple]int[/purple] i, j, x, tmp;
     j = p - 1;
     x = t[r];
     [b][blue]for[/blue][/b](i=p ; i<r ; i++)
     {
         [b][blue]if[/blue][/b](x > t[i ])
         {
             j++;
             tmp = t[j];
             t[j] = t[i ];
             t[i ] = tmp;
         }
     }
     t[r] = t[j+1];
     t[j+1] = x;
     [b][blue]return[/blue][/b] j + 1;
}

static void Filled_polygon_quicksord(int* t, [purple]int[/purple] p, [purple]int[/purple] r) [green]//from MonochromeLib by PierrotLL[/green]
{
     [purple]int[/purple] q;
     [b][blue]if[/blue][/b](p < r)
     {
         q = Filled_polygon_quicksord_partition(t, p, r);
         Filled_polygon_quicksord(t, p, q-1);
         Filled_polygon_quicksord(t, q+1, r);
     }
}


void Filled_polygon(const [purple]int[/purple] *x, const [purple]int[/purple] *y, [purple]int[/purple] nb_vertices, unsigned short color) [green]//from MonochromeLib by PierrotLL[/green]
{
     [purple]int[/purple] i, j, dx, dy, ymin, ymax;
     [purple]int[/purple] *cut_in_line, nb_cut;
     [b][blue]if[/blue][/b](nb_vertices < 3) [b][blue]return[/blue][/b];
     cut_in_line = malloc(nb_vertices*sizeof(int));
     [b][blue]if[/blue][/b](!cut_in_line) [b][blue]return[/blue][/b];
     ymin = ymax = y[0];
     [b][blue]for[/blue][/b](i=[maroon]1[/maroon] ; i<nb_vertices ; i++)
     {
         [b][blue]if[/blue][/b](y[i ] < ymin) ymin = y[i ];
         [b][blue]if[/blue][/b](y[i ] > ymax) ymax = y[i ];
     }
     [b][blue]for[/blue][/b](i=ymin ; i<=ymax ; i++)
     {
         nb_cut = [maroon]0[/maroon];
         [b][blue]for[/blue][/b](j=[maroon]0[/maroon] ; j<nb_vertices ; j++)
         {
             [b][blue]if[/blue][/b]((y[j]<=i && y[(j+1)%nb_vertices]>=i) || (y[j]>=i && y[(j+1)%nb_vertices]<=i))
             {
                 dy = abs(y[j]-y[(j+1)%nb_vertices]);
                 [b][blue]if[/blue][/b](dy)
                 {
                     dx = x[(j+1)%nb_vertices]-x[j];
                     cut_in_line[nb_cut] = x[j] + [b][green]/*random*/[/green][/b](abs(i-y[j]+sgn(i-y[j])/2)*dx/dy);
                     nb_cut++;
                 }
             }
         }
         Filled_polygon_quicksord(cut_in_line, [maroon]0[/maroon], nb_cut-1);
         j = [maroon]0[/maroon];
         [b][blue]while[/blue][/b](j<nb_cut-2 && cut_in_line[j]==cut_in_line[j+1]) j++;
         [b][blue]while[/blue][/b](j < nb_cut)
         {
             [b][blue]if[/blue][/b](j == nb_cut-1) Horizontal_Line(cut_in_line[j-1]+1, cut_in_line[j], i, color);
             [b][blue]else[/blue][/b]
             {
                 dx = [maroon]1[/maroon];
                 [b][blue]while[/blue][/b](j+dx<nb_cut-1 && cut_in_line[j+dx]==cut_in_line[j+dx+1]) dx++;
                 Horizontal_Line(cut_in_line[j], cut_in_line[j+dx], i, color);
                 j += dx;
             }
             j++;
         }
     }
     free(cut_in_line);
}

[brown]#define abs(a) ((a) < 0 ? -(a) : (a))[/brown]
[brown]#define min(a,b) (((a) < (b))? (a) : (b))[/brown]
[brown]#define max(a,b) (((a) > (b))? (a) : (b))[/brown]
[brown]#define sgn(a) ((a) < 0 ? (-1) : (a) > 0 ? (1) : (a))[/brown]


void Horizontal_Line(int x1, [purple]int[/purple] x2, [purple]int[/purple] y, unsigned short color)
{
     unsigned short* VRAM = GetVRAMAdress();
     [purple]int[/purple] i;
     [purple]int[/purple] xi = max(min(x1,x2),[maroon]0[/maroon]);
     [purple]int[/purple] xf = min(max(x1,x2),LCD_WIDTH_PX);
     [b][blue]if[/blue][/b](y < 0 || y > LCD_HEIGHT_PX) [b][blue]return[/blue][/b];
     [b][blue]for[/blue][/b](i=xi; i <= xf; i++)
     VRAM[LCD_WIDTH_PX*y + i] = color;
}

Afficher du texte
Afficher du texte
void text_printC(int x, [purple]int[/purple] y, [purple]char[/purple] c, [purple]int[/purple] size, [purple]int[/purple] color)
{
    [purple]int[/purple] i, j, byte_width, alpha;
    char* data;
    [b][blue]if[/blue][/b](c<32 || c>127 || size<1) [b][blue]return[/blue][/b];
    byte_width = ((used_font[b]->[/b]width-1)>>3)+1;
    data = used_font[b]->[/b]data + byte_width * used_font[b]->[/b]height * (c-32);
    alpha = [maroon]32[/maroon] - ((color>>16) % 32);
    color &= [maroon]0[/maroon]xFFFF;
    [b][blue]for[/blue][/b](i=[maroon]0[/maroon] ; i<used_font[b]->[/b]height ; i++) {
        [b][blue]for[/blue][/b](j=[maroon]0[/maroon] ; j<used_font[b]->[/b]width ; j++) {
            [b][blue]if[/blue][/b](data[i*byte_width+(j>>3)] & (128>>(j&7)))
                text_drawPoint(x+j*size, y+i*size, size, color, alpha);
            [b][blue]else[/blue][/b] if(used_font[b]->[/b]flags & ANTIALIASING) { [green]// Antialiasing[/green]
                [b][blue]if[/blue][/b](text_readPix(data, j, i-1, used_font[b]->[/b]width, used_font[b]->[/b]height)) {
                    [b][blue]if[/blue][/b](text_readPix(data, j-1, i, used_font[b]->[/b]width, used_font[b]->[/b]height)) text_antialias(x+j*size, y+i*size, size, color, alpha, [maroon]0[/maroon]);
                    [b][blue]if[/blue][/b](text_readPix(data, j+1, i, used_font[b]->[/b]width, used_font[b]->[/b]height)) text_antialias(x+j*size, y+i*size, size, color, alpha, [maroon]1[/maroon]);
                }
                [b][blue]if[/blue][/b](text_readPix(data, j, i+1, used_font[b]->[/b]width, used_font[b]->[/b]height)) {
                    [b][blue]if[/blue][/b](text_readPix(data, j-1, i, used_font[b]->[/b]width, used_font[b]->[/b]height)) text_antialias(x+j*size, y+i*size, size, color, alpha, [maroon]2[/maroon]);
                    [b][blue]if[/blue][/b](text_readPix(data, j+1, i, used_font[b]->[/b]width, used_font[b]->[/b]height)) text_antialias(x+j*size, y+i*size, size, color, alpha, [maroon]3[/maroon]);
                }
            }
        }
    }
}

void text_print(int x, [purple]int[/purple] y, char* c, [purple]int[/purple] size, [purple]int[/purple] color)
{
    [purple]int[/purple] save_x = x;
    [b][blue]for[/blue][/b]( ; *c ; c++) {
        [b][blue]if[/blue][/b](*c == [gray]'\n'[/gray]) {
            x = save_x;
            y += (used_font[b]->[/b]height + used_font[b]->[/b]height/2) * size;
        } [b][blue]else[/blue][/b] {
            text_printC(x, y, *c, size, color);
            x += size * text_widthC(*c);
        }
    }
}

Affiche un sprite
Affiche un sprite
void CopySpriteNbitMasked(const unsigned char* data, int x, int y, int width, int height, const short* palette, short maskColor, unsigned int bitwidth)
{
    short* VRAM = (short*)0xA8000000; //ou  color_t* VRAM = (color_t*) GetVRAMAddress();
    int offset = 0;
    int availbits ;
    int j,i;
    unsigned char buf;
    short thiss;
    short color;

    VRAM += (128*3*y + x);
    for(j=y; j<y+height; j++)
    {
        availbits = 0;

        for(i=x; i<x+width;  i++)
        {
            if (!availbits)
            {
                buf = data[offset++];
                availbits = 8;
            }
            thiss = ((short)buf>>(8-bitwidth));
            color = palette[thiss];
            if(color != maskColor && i >= 0 && i<384)
            {
                *VRAM = color;
            }
            VRAM++;
            buf<=bitwidth;
            availbits-=bitwidth;
        }
        VRAM += (128*3-width);
    }
}

Affiche un sprite (en 16 bit)
Affiche un sprite (en 16 bit)
void CopySpriteMasked(short* bitmap, int x, int y, int width, int height, short mask)
{
    short* VRAM = (short*)0xA8000000;

    int y_index;
    int x_index;
    short * base = y * 128*3 + x + VRAM;
    for (y_index = height; y_index > 0; --y_index, base += 128*3 - width) {
        for (x_index = width; x_index > 0; --x_index, ++base, ++bitmap) {
            if (*bitmap != mask) *base = *bitmap;
        }
    }
}

Affiche un sprite 16 bit avec de la transparence
Affiche un sprite 16 bit avec de la transparence
void alphaSprite(int x, int y, int width, int height, short* bitmap, short alpha)
{
    short* VRAM = (short*)0xA8000000;
    int x_inc = width;
    if (y < 0)
    {
        bitmap -= y * width;
        height += y;
        y = 0;
    }
    if (height > 216 - y) height = 216 - y;

    if (x < 0)
    {
        bitmap -= x;
        width += x;
        x = 0;
    }
    if (width > 128*3 - x) width = 128*3 - x;

    x_inc -= width;

    int y_index;
    int x_index;
    short * base = y * 128*3 + x + VRAM;
    for (y_index = height; y_index > 0; y_index--, base += 128*3 - width, bitmap += x_inc)
    {
        for (x_index = width; x_index > 0; x_index--, base++ , bitmap++ )
        {
            if (*bitmap!=alpha && *bitmap!= 0xffff) *base = *bitmap;
        }
    }
}

Afficher des sprites avec de la transparence
Afficher des sprites avec de la transparence
void CopySpriteNbitMaskedAlpha(const unsigned char* data, [purple]int[/purple] x, [purple]int[/purple] y, [purple]int[/purple] width, [purple]int[/purple] height, const color_t* palette, color_t maskColor, [purple]unsigned int[/purple] bitwidth,int alpha)
{
    color_t* VRAM = (color_t*) GetVRAMAdress();
    VRAM += (LCD_WIDTH_PX*y + x);
    alpha %= [maroon]32[/maroon];
    [purple]int[/purple] i,j;
    [purple]int[/purple] offset = [maroon]0[/maroon];
    [purple]unsigned char[/purple] buf=[maroon]0[/maroon];
    [b][blue]for[/blue][/b](j=y; j<y+height; j++)
    {
       [purple]int[/purple] availbits = [maroon]0[/maroon];
       [b][blue]for[/blue][/b](i=x; i<x+width;  i++)
       {
          [b][blue]if[/blue][/b] (!availbits)
          {
             buf = data[offset++];
             availbits = [maroon]8[/maroon];
          }
          color_t thiss = ((color_t)buf>>(8-bitwidth));
          color_t color = palette[thiss];
          [b][blue]if[/blue][/b](color != maskColor&& i >=[maroon]0[/maroon] && i<384)
             *VRAM = ((((color & 0xF81F) * alpha + (*VRAM & 0xF81F) * (32-alpha)) >> 5) & 0xF81F) |
             ((((color & 0x07E0) * alpha + (*VRAM & 0x07E0) * (32-alpha)) >> 5) & 0x07E0);
          VRAM++;
          buf<<=bitwidth;
          availbits-=bitwidth;
       }
       VRAM += (LCD_WIDTH_PX-width);
    }
}



Transforme un entier en une chaîne de caractères
Transforme un entier en une chaîne de caractères
char* int2str(char* c, [purple]int[/purple] n)
{
    [b][blue]if[/blue][/b](n==[maroon]0[/maroon])
    {
        c[0] = [gray]'0'[/gray];
        c[1] = [maroon]0[/maroon];
    }
    [b][blue]else[/blue][/b]
    {
        [purple]int[/purple] i, l=[maroon]0[/maroon];
        [b][blue]for[/blue][/b](i=n ; i ; i/=[maroon]10[/maroon])
            l++;
        c[l] = [maroon]0[/maroon];
        [b][blue]for[/blue][/b](i=n ; i ; i/=[maroon]10[/maroon])
            c[--l] = i%10+[gray]'0'[/gray];
    }
    [b][blue]return[/blue][/b] c;
}

Abs
Abs
unsigned [purple]int[/purple] abs(int i){
      [b][blue]return[/blue][/b] (i<0?-i:i);
}

Nombre au hasard
Chiffre au hasard
unsigned [purple]int[/purple] random(int seed, [purple]int[/purple] value) [green]// Function from Simon Lothar[/green]
{
    static [purple]unsigned int[/purple] lastrandom = [maroon]0[/maroon]x12345678;
    [b][blue]if[/blue][/b](seed) lastrandom = seed;
    lastrandom = (0x41C64E6D * lastrandom) + 0x3039;
    [b][blue]return[/blue][/b] ((lastrandom >> 16) % value);
}

Réglage des fps
Réglage des fps
void setFps(int fpsWish) [green]//1 pour 128, [maroon]2[/maroon] pour 64, [maroon]3[/maroon] pour 42, [maroon]128[/maroon]/fpsWish en fait[/green]
{
     static [purple]unsigned int[/purple] fps = [maroon]0[/maroon], fps_count = [maroon]0[/maroon];

     [b][blue]do[/blue][/b]
     {
         fps = RTC_GetTicks();
     }
     [b][blue]while[/blue][/b](fps < fps_count+fpsWish);
     fps_count = RTC_GetTicks();
}




N'hésitez pas à exposez ici vos plus belles découvertes !


ColorLib regroupe toutes ses fonctions




Pages : Précédente1, 2, 3, 4, 5
Alex BasicCHors ligneAncien modérateurPoints: 1734 Défis: 83 Message

Citer : Posté le 18/08/2016 14:00 | #


Merci Lephenixnoir

@Nemhardy : j'avais essayé et il me sortait une autre erreur :/ la lib n'existe vraiment pas dans le sdk
NemhardyHors ligneGrand maître des Traits d'EspritPoints: 1235 Défis: 54 Message

Citer : Posté le 18/08/2016 14:36 | #


Ben j'ai déjà réussi à utiliser des fonctions mathématiques comme ça, du coup ça m'étonne un peu, j'essaierai de regarder quand j'aurai le bon PC sous la main.
N'attendez pas qu'il n'y ait plus de miel : スススススススススススススススススススススススススス養蜂家スススススススススススススススススススススススススススススススススススス蜂家
Pages : Précédente1, 2, 3, 4, 5

Planète Casio v42 © créé par Neuronix et Muelsaco 2004 - 2019 | Il y a 26 connectés | Nous contacter | Qui sommes-nous ? | Licences et remerciements

Planète Casio est un site communautaire non affilié à Casio. Toute reproduction de Planète Casio, même partielle, est interdite.
Les programmes et autres publications présentes sur Planète Casio restent la propriété de leurs auteurs et peuvent être soumis à des licences ou copyrights.
CASIO est une marque déposée par CASIO Computer Co., Ltd