Radial gradient fill improvement
Attempting to improve fading out to edges (so the actual effect is more obvious).
This commit is contained in:
parent
2b39f8cc03
commit
f40dc07f37
1 changed files with 15 additions and 11 deletions
|
|
@ -250,8 +250,10 @@ void draw_radial_gradient(SDL_Surface * canvas, int x_left, int y_top, int x_rig
|
|||
Uint8 draw_r, draw_g, draw_b, old_r, old_g, old_b, new_r, new_g, new_b;
|
||||
|
||||
/* Calculate the max radius of the filled area */
|
||||
xd = (x_right - x_left + 1);
|
||||
yd = (y_bottom - y_top + 1);
|
||||
//xd = (x_right - x_left + 1);
|
||||
//yd = (y_bottom - y_top + 1);
|
||||
xd = max(abs(x - x_right), abs(x - x_left));
|
||||
yd = max(abs(y - y_bottom), abs(y - y_top));
|
||||
rad = sqrt(xd * xd + yd * yd);
|
||||
if (rad == 0) {
|
||||
return;
|
||||
|
|
@ -269,6 +271,7 @@ void draw_radial_gradient(SDL_Surface * canvas, int x_left, int y_top, int x_rig
|
|||
xd = (float) abs(xx - x);
|
||||
yd = (float) abs(yy - y);
|
||||
dist = sqrt(xd * xd + yd * yd);
|
||||
if (dist < rad) {
|
||||
ratio = (dist / rad);
|
||||
|
||||
/* Get the old color, and blend it (with a distance-based ratio) with the target color */
|
||||
|
|
@ -285,4 +288,5 @@ void draw_radial_gradient(SDL_Surface * canvas, int x_left, int y_top, int x_rig
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue