I am building a UWF program and I want to make it so every x seconds 3 random squares change color.
There are around 40 squares in total and each of them are named rec1 - rec42. So my thinking was to randomly pick a square by combining two strings, "rec" and a random int. But now I have to set a field from a string is that even possible? Am I even understanding/approaching this right?
This is my current method
void animatedGraphics_Tick(object sender, object e) {
//List of color
String[] possibleColor = { "#FF443806", "#FF332E04", "#FF130F03" };
Random rnd = new Random();
//Loop for three square
for (int i = 0; i < 3; i++)
{
//generate pick squares to change
string square = ("rec" + rnd.Next(1, 43));
//Something like square.fill = possibleColor[rnd.Next(0,3)];
}
}
Thanks
edit: This is what I ended up using
void animatedGraphics_Tick(object sender, object e)
{
//List of color converted to from ARGB values
Color[] possibleColor = { Color.FromArgb(255, 65, 54 ,9),
Color.FromArgb(255, 19, 15, 3), Color.FromArgb(255, 51, 46, 3) };
Random rnd = new Random();
//Loop for three square
for (int i = 0; i < 3; i++)
{
//Use FindName to locate the shape
Rectangle square = (Rectangle) this.FindName("rec" + rnd.Next(1,42));
//Change the shape color
square.Fill = new SolidColorBrush(possibleColor[rnd.Next(0,3)]);
}
}