bx_blend_color.c
Computes an approximation of the color c of an alpha-weighted blend of two colors c1 and c2, that is if c1=(r1,g1,b1) and c2=(r2,g2,b2) as (Red,Green,Blue) triplets, then c=(r1+(r2-r1)*alpha, g1+(g2-g1)*alpha, b1+(b2-b1)*alpha) for some given alpha in the range (0.0, 1.0).
- Parameters:
-
| c1 | the first color. |
| c2 | the second color. |
| alpha | a blending coefficient in the range (0.0, 1.0). |
- Returns:
- the blend of c1 and c2 by coefficient alpha.
#include <bx.h>
int main (void)
{
bx_window win;
bx_color c1, c2, c3, c4, c5;
int w= 180, h= 60;
bx_init ();
win= bx_create_window ("bx_mean_color", 10 , 10, w, h);
c1= bx_pink (); c5= bx_orange ();
c2= bx_blend_color (c1, 0.25, c5);
c3= bx_blend_color (c1, 0.50, c5);
c4= bx_blend_color (c1, 0.75, c5);
bx_set_color (c1); bx_draw_box (win, 0*w/5, 0, w/5, h, BX_FILLED);
bx_set_color (c2); bx_draw_box (win, 1*w/5, 0, w/5, h, BX_FILLED);
bx_set_color (c3); bx_draw_box (win, 2*w/5, 0, w/5, h, BX_FILLED);
bx_set_color (c4); bx_draw_box (win, 3*w/5, 0, w/5, h, BX_FILLED);
bx_set_color (c5); bx_draw_box (win, 4*w/5, 0, w/5, h, BX_FILLED);
bx_show_canvas (win, 0);
bx_loop();
return 0;
}