1 Replies - 378 Views - Last Post: 02 March 2013 - 12:05 PM Rate Topic: -----

#1 catvsrat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-February 13

Fading color using frequency and amplitude

Posted 28 February 2013 - 06:35 PM

I have a program that fades two RGB colors. Since the fading of color can be interpreted as a wave, i want to know how do i change my update color function so that i can define a frequency and amplitude. I want to make the fading go fast if i increase the frequency and get bigger circles when i increase the amplitude.Can you provide me the mathematical formula.How do i change the code below to incorporate that. Any help, thanks.

bool updateColorValue(float &currentValue, uchar goalValue, 
          float deltaValue, Lights::MSecs dtime)
{
  if (deltaValue == 0) return true;
    currentValue += deltaValue * dtime; 
if ((deltaValue < 0 && currentValue <= goalValue) || 
   (deltaValue > 0 && currentValue >=   goalValue)) {

     currentValue = goalValue;
     return true;
 } else return false;
}

void setCurrentGoal (uint goalNum) {
_currentGoal = goalNum;
RGB color = _goalColors[_currentGoal];
_deltaColor.R = (color.R - _currentColor.R)/(double)_period;
_deltaColor.G = (color.G - _currentColor.G)/(double)_period;
_deltaColor.B = (color.B - _currentColor.B)/>/(double)_period;
}




Is This A Good Question/Topic? 0
  • +

Replies To: Fading color using frequency and amplitude

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,140
  • Joined: 14-September 07

Re: Fading color using frequency and amplitude

Posted 02 March 2013 - 12:05 PM

I found this tutorial to be pertinent to your needs.

Quote

Monochromatic light is light made up of one single pure frequency (this is certainly not the general case, most light you see is multichromatic). Monochromatic light looks to the eye as a pure color, and can never be white or magenta. Since it contains only one frequency, the wave of monochromatic light can be represented as a sine:

Posted Image

The height of the sine is the amplitude or how bright the light is. The width of one period (called lambda) is the wavelength of the light, and is inversely related to the frequency: since the light travels at 300000000 m/s, it's wavelength is 300000000/f where f is the frequency. So the visible spectrum of light has wavelengths from around 400 to 700 nm.(1 nm = 10^-9 meter).

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1