SFML community forums

Help => Graphics => Topic started by: Foaly on September 10, 2012, 07:50:09 pm

Title: Color transmission is not smooth
Post by: Foaly on September 10, 2012, 07:50:09 pm
Hi there,
a while back I was looking for a way to make a transition between multiple colors. Thread: http://en.sfml-dev.org/forums/index.php?topic=7996.msg54612 (http://en.sfml-dev.org/forums/index.php?topic=7996.msg54612) The other day I picked the project up again and I came up with the following solution: Changing the hue over time and then calculating the RGB from that. I implemented the following code:
        hue += 0.5 * fTime;
        if(hue > 1.0)
            hue = 0.0;

        float r = abs(3.0 - 6.0 * hue) - 1.0;
        float g = 2.0 - abs(2.0 - 6.0 * hue);
        float b = 2.0 - abs(4.0 - 6.0 * hue);

        color = sf::Color(CLAMP(r, 0.f, 1.f) * 255.f, CLAMP(g, 0.f, 1.f) * 255.f, CLAMP(b, 0.f, 1.f) * 255.f);
 
I doesn't give the results i expected though... The transitions are choppy and not all colors are shown. It looks like this:

(http://img6.imagebanana.com/img/ae752wvo/Unbenannt.png)

I don't really know why. The calculation seem to be right. Does anybody know what's wrong?
Title: Re: Color transmission is not smooth
Post by: Marukyu on September 12, 2012, 10:39:01 am
Make sure CLAMP() returns a float, not an int.
Title: Re: Color transmission is not smooth
Post by: Foaly on September 12, 2012, 11:53:15 am
Nevermind I found the error... CLAMP() is a template so there was nothing wrong with that. But my abs() returned an int and therefore jumped between 0 and 1. Using std::abs() solved the problem :) But thanks!