Exact Gradient?

Non-platform specific questions.

Exact Gradient?

Postby Hblade » Sun Apr 01, 2012 11:26 pm

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?
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Exact Gradient?

Postby skydereign » Sun Apr 01, 2012 11:38 pm

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);
    }
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Exact Gradient?

Postby Hblade » Sun Apr 01, 2012 11:58 pm

This is awesome. Thanks a ton! +1
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest