Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok, If I understand you right, you want to fade from Red, to green to blue?</p> <p>Starting off with a struct and an enum to hold our color data and state.</p> <pre><code>public enum PrimaryColor { Red, Green, Blue } public struct Color { public byte r; public byte g; public byte b; public Color(byte r, byte g, byte b) { this.r = r; this.g = g; this.b = b; } } </code></pre> <p>We then make some variables to hold our state data, including an array of which we will traverse.</p> <pre><code>Color ActualColor = new Color(255, 0, 0); int State = 0; PrimaryColor[] Order = { PrimaryColor.Red, PrimaryColor.Green, PrimaryColor.Blue }; </code></pre> <p>Then, in your update function (say a timer, or while loop, etc.) we add a little switch statement to update colors, check for byte underflow and change states.</p> <pre><code>switch (Order[State]) { case PrimaryColor.Red: ActualColor.r++; if(ActualColor.g &gt; 0) ActualColor.g--; if (ActualColor.b &gt; 0) ActualColor.b--; if (ActualColor.r == 255 &amp;&amp; ActualColor.g == 0 &amp;&amp; ActualColor.b == 0) State++; break; case PrimaryColor.Green: ActualColor.g++; if (ActualColor.r &gt; 0) ActualColor.r--; if (ActualColor.b &gt; 0) ActualColor.b--; if (ActualColor.r == 0 &amp;&amp; ActualColor.g == 255 &amp;&amp; ActualColor.b == 0) State++; break; case PrimaryColor.Blue: ActualColor.b++; if (ActualColor.g &gt; 0) ActualColor.g--; if (ActualColor.r &gt; 0) ActualColor.r--; if (ActualColor.r == 0 &amp;&amp; ActualColor.g == 0 &amp;&amp; ActualColor.b == 255) State++; break; default: break; } if (State == Order.Length) State = 0; //Send color data to your controller </code></pre>
 

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