Page 1 of 1

Exact Gradient?

PostPosted: Sun Apr 01, 2012 11:26 pm
by Hblade
I'd like to know how to create a gradient using a canvas, and it's always the same gradient (of course, editing the RGB), but its always the same no matter the size of the canvas. An example would be, if you had something going from black to white, the top pixel would be black (Filling hte gradient), and the bottom pixel would be black. I know this produces lag, but if it only updates once (Say in Create Actor) all should be well. How would I go about doing this?

Re: Exact Gradient?

PostPosted: Sun Apr 01, 2012 11:38 pm
by skydereign
You mean like this? You could mod it a bit to support multiple directions and other. But, this will create an even gradient from one color to the other.
Code: Select all
void
draw_gradient (int r1, int g1, int b1, int r2, int g2, int b2)
{
    int i;
    double ratio;
    for(i=0;i<width;i++)
    {
        ratio = (double)i/width;
        setpen(r1+ratio*(r2-r1), g1+ratio*(g2-g1), b1+ratio*(b2-b1), 0, 1);
        moveto(i, 0);
        lineto(i, height);
    }
}

Re: Exact Gradient?

PostPosted: Sun Apr 01, 2012 11:58 pm
by Hblade
This is awesome. Thanks a ton! +1