Dear SDL dudez & Sammy:
I would like to know if any of you know how to write gradient code that
starts with any RGB value and ends with any RGB value. Currently I only
know how to create gradients that use only red, or only green, or
combinations of red and green, etc. green and blue…etc…
For example, if you want it to grade from red to black use:
Horiz_Gradient(SDL_Surface *screen, 0, 0, 100, 100, 1, 0, 0,
LIGHT_TO_DARK)
Or you can use both red and green and it will grade using yellow to
black. I would like to know if anyone here knows how to grade from to . Not just to black. This would totally rox ma
bong.
I’ve thought about it…seems like I would somehow have to calculate the
difference between the two values, then proportionally move from one
color to the other depending on the width of the gradient.
Horiz_Gradient(SDL_Surface *screen, Uint16 x1, Uint16 y1, Uint16 x2,
Uint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 spec) {
Uint16 line, color;
Uint8 count;
Uint8 null = 0;
Uint8 *red, *green, *blue;
Uint16 width, height;
width = x2 - x1;
height = y2 - y1;
if® red = &count;
else red = &null;
if(g) green = &count;
else green = &null;
if(b) blue = &count;
else blue = &null;
#ifdef DEBUG
printf(“Gradient: X: %u Y: %u Width: %u Height: %u\n”, x1, y1, width,
height);
#endif
for(line = 0; line < width; line++) {
count = line * 255 / width;
PIXEL_FROM_RGB(color, screen->format, *red, *green, *blue);
if(spec == DARK_TO_LIGHT)
Verti_Line(screen, x1 + line, y1, y2, color);
if(spec == LIGHT_TO_DARK)
Verti_Line(screen, x2 - line, y1, y2, color);
} /* end of line for */
} /* end of function */
Thanx,
Paul Lowe
spazz at ulink.net