Fading colors - how to?
Displaying 1-6 of 6 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
blues_zodiakos

Sorry for posting two questions so close together, but they are different. :D

How would I go about, for example, fading a blue pixel to yellow slowly? I've tried all sorts of weird calculations, and most of them result in the blue pixel changing every color EXCEPT yellow until the last frame. My ultimate goal would be to take a starting color, an ending color, and a speed, and be able to do the fade with those 3 variables.

Posted on 2005-01-15 13:40:38

Ness

Something like this?


//start color
int color = RGB(0, 0, 255);

//end color
int endcolor = RGB(254, 254, 1);

int speed = 100; //1 second (hah! not really)

//start color components (these change)
int r,g,b;
//final color components
int fr, fg, fb;
//how much to change each color every cycle
int dr, dg, db;

r = getR(color);
g = getG(color);
b = getB(color);

fr = getR(endcolor);
fg = getG(endcolor);
fb = getB(endcolor);

dr = (fr-r)/speed;
dg = (fg-g)/speed;
db = (fb-b)/speed;

while(r != fr && b != fb && g != fg)
{
r += dr;
g += dg;
b += db;

color = RGB(r, g, b);

RectFill(0, 0, 320, 340, color, screen);
showpage();
}

while(!b1)
{
RectFill(0, 0, 320, 340, color, screen);
showpage();
}


There is a problem, because of integer math the the ratios (dr, dg, db) won't be exactly perfect. Like how I had to fade to RGB(254, 254, 1) instead of RGB(255, 255, 0) for yellow

Posted on 2005-01-15 14:30:33

blues_zodiakos

Thanks! I'll have to try this when I get home. I'll tell you how it goes. I'm making a much improved version of my particle engine, and this was one of the things I NEEDED. :D

Posted on 2005-01-15 16:24:16

RageCage

I suggest you take a look at the mixColor() function here.


//start color
int strtcolor = RGB(0, 0, 255);

//end color
int endcolor = RGB(255, 255, 0);

int speed = 100; //1 second (truely this time)
int timeStamp=timer;
while(timer-timeStamp < speed)
{
color = mixColor(strtcolor, endcolor, timer-timeStamp * 255 / speed)

RectFill(0, 0, 320, 340, color, screen);
showpage();
}

while(!b1)
{
RectFill(0, 0, 320, 340, color, screen);
showpage();
}

Posted on 2005-01-16 10:19:28 (last edited on 2005-01-16 10:22:32)

Ness

Yeah you have to go and do it the right way..:p

Posted on 2005-01-16 15:30:24

blues_zodiakos

So THAT'S what mixcolor does. It looked like the function to experiment with, but I wasn't sure. :D

Posted on 2005-01-17 13:10:49


Displaying 1-6 of 6 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.