Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Color transmission is not smooth  (Read 1977 times)

0 Members and 1 Guest are viewing this topic.

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Color transmission is not smooth
« 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 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:



I don't really know why. The calculation seem to be right. Does anybody know what's wrong?

Marukyu

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: Color transmission is not smooth
« Reply #1 on: September 12, 2012, 10:39:01 am »
Make sure CLAMP() returns a float, not an int.

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Color transmission is not smooth
« Reply #2 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!

 

anything