1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| void bresenham_cercle (image I, int rayon, int x_centre, int y_centre, byte r, byte g, byte b, byte a)
{
int x, y, m;
int octant1, octant2, octant3, octant4, octant5, octant6, octant7, octant8;
x = 0;
y = rayon;
m = 5 - (4 * rayon);
while (x <= y)
{
colour* ptr = NULL;
/*Octants de 1 à 8, dans le sens des aiguilles d'un montre*/
octant1 = (-y + y_centre) * I->w + (x + x_centre);
octant2 = (-x + y_centre) * I->w + (y + x_centre);
octant3 = (x + y_centre) * I->w + (y + x_centre);
octant4 = (y + y_centre) * I->w + (x + x_centre);
octant5 = (y + y_centre) * I->w + (-x + x_centre);
octant6 = (x + y_centre) * I->w + (-y + x_centre);
octant7 = (-x + y_centre) * I->w + (-y + x_centre);
octant8 = (-y + y_centre) * I->w + (-x + x_centre);
ptr = I->pixel + octant1;
if (octant1 > 0 && octant1 < I->w * I->h)
image_putpixel_alpha (ptr, r, g, b, a);
ptr = I->pixel + octant2;
if (octant2 > 0 && octant2 < I->w * I->h )
image_putpixel_alpha (ptr, r, g, b, a);
ptr = I->pixel + octant3;
if (octant3 < I->w * I->h && octant3 > 0 )
image_putpixel_alpha (ptr, r, g, b, a);
ptr = I->pixel + octant4 ;
if (octant4 < I->w * I->h && octant4 > 0 )
image_putpixel_alpha (ptr, r, g, b, a);
ptr = I->pixel + octant5 ;
if (octant5 < I->w * I->h && octant5 > 0 )
image_putpixel_alpha (ptr, r, g, b, a);
ptr = I->pixel + octant6;
if (octant6 > 0 && octant6 < I->w * I->h )
image_putpixel_alpha (ptr, r, g, b, a);
ptr = I->pixel + octant7;
if (octant7 > 0 && octant7 < I->w * I->h )
image_putpixel_alpha (ptr, r, g, b, a);
ptr = I->pixel + octant8;
if (octant8 > 0 && octant8 < I->w * I->h )
image_putpixel_alpha (ptr, r, g, b, a);
if (m > 0)
{
y--;
m = m - 8 * y;
}
x++;
m = m + (8 * x) + 4;
}
} |
Partager