Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Colours are usually specified as quantities of red, green and blue light. For most purposes, 8-bit resolution in each colour component (red, green, or blue) is sufficient.</p> <p>So you might have a colour struct like this:</p> <pre><code>typedef unsigned char uint8; struct Colour { uint8 red; uint8 green; uint8 blue; Colour(uint8 r, uint8 g, uint8 b) : red(r), green(g), blue(b) {} }; </code></pre> <p>then you can make colours once you understand the RGB colour model. For your example colours, this is pretty easy:</p> <pre><code>Colour Red(255, 0, 0); Colour Blue(0, 0, 255); </code></pre> <p>Let's say you want to change from blue to red over 100 steps (or 100 seconds, or whatever). You simply increment each component from the source value to the target value, so in your case, blue to red would be:</p> <ul> <li>Red: 0 to 255 </li> <li>Green: 0 to 0 </li> <li>Blue: 255 to 0</li> </ul> <p>So the red component is faded up to full intensity as you move to red, and the blue component is faded down to zero.</p> <p>Some simple code to do this:</p> <pre><code>// Fade from blue to red Colour Source(0, 0, 255); // blue Colour Target(255, 0, 0); // red Colour MyColour = Source; const int NumSteps = 100; for (int i = 0; i &lt;= NumSteps; i++) { MyColour.red = Source.red + (((Target.red - Source.red) * i) / NumSteps); MyColour.green = Source.green + (((Target.green - Source.green) * i) / NumSteps); MyColour.blue = Source.blue + (((Target.blue - Source.blue) * i) / NumSteps); // Do something, like update the display DoSomethingWithColour(MyColour); } </code></pre> <p>This will fade MyColour from blue to red. Note that this will fade through the RGB colour space.</p> <p>There are other colour spaces, such as HLS and HSV, and fading through those colour spaces will give different effects. For example, halfway through the RGB fade above the colour will be RGB(128, 0, 128), which is purple. If you fade through the HSV space, the hue component will fade from red to purple to blue, so in this case it is the same. However, if you choose different colours, you may get different effects depending on which colour space you use.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload