I wanted to generate a 7 segment display whose color brightness varies with time, this can be done by just using linear relationship.
Color activeColour2 = new Color(1, DateTime.Now.Millisecond*0.001f, DateTime.Now.Millisecond*0.001f);
So in 1 complete second, it produce color in the range of (1,0,0) to (1,1,1) as in the code below:
using System;
using UnityEngine;
public class ClockDigit2 : MonoBehaviour
{
static readonly bool[,] SEGMENT_IS_ACTIVE = new bool[,] {
{true, true, true, true, true, true, false}, // 0
{false, true, true, false, false, false, false}, // 1
{true, true, false, true, true, false, true }, // 2
{true, true, true, true, false, false, true }, // 3
{false, true, true, false, false, true, true }, // 4
{true, false, true, true, false, true, true }, // 5
{true, false, true, true, true, true, true }, // 6
{true, true, true, false, false, false, false}, // 7
{true, true, true, true, true, true, true }, // 8
{true, true, true, true, false, true, true } // 9
};
public Color32 inactiveColour = Color.black;
public SpriteRenderer[] segments = new SpriteRenderer[7];
public void Display(int number)
{
Color activeColour2 = new Color(1, DateTime.Now.Millisecond*0.001f, DateTime.Now.Millisecond*0.001f);
var digit = number % 10;
if (digit < 0) digit *= -1;
for (int i = 0; i < 7; i++)
{
if (SEGMENT_IS_ACTIVE[digit, i])
{
segments[i].color = activeColour2;
}
else
{
segments[i].color = inactiveColour;
}
}
}
void Update()
{
Display(DateTime.Now.Second);
}
}
However, now I want to interpolate through all the colors in the circle above over 1 second.
I don't know how to express this as a formula for R, G, and B. The RGB value is not linear relationship: as you spin the selected color in the chart, you can notice the RGBA components vary together in a nonlinear form.
I considered using Lagrangian interpolation. However, this will not be accurate or might fail greatly because if you take a reference point at the circle and assume in 1sec, it made a complete revolution, you will notice there is a certain period of time where the RGB value is constant along the path: either 0 and 1.
So is there any method to get a formula that perfectly fits the color chart with respect to time?