So I am using a C# WebBrowser control and am trying to convert a string into an HTML/CSS rainbow. Currently I simply randomly generate 1000 colors in hex format and iterate through each char in the string adding a span
style color:(hex value)
for each char. It works but I would like the colors to merge together for a more rainbow effect. Is this possible? Here is my current function:
public static string Rainbow(string text)
{
int numColors = 1000;
var colors = new List<string>();
var random = new Random();
for (int i = 0; i < numColors; i++)
{
colors.Add(String.Format("#{0:X6}", random.Next(0x1000000)));
}
string rainbow = "";
int index = 0;
foreach (char c in text)
{
rainbow += String.Format("<span style='color: {0};'>{1}</span>", colors[index], c.ToString());
if (index > numColors)
index = 0;
else
index++;
}
return rainbow;
}