|
-
July 10th, 2012, 10:11 AM
#1
[RESOLVED] Changing color based on a duration
I'm working on coloring a component based on the time since its last update. I would like it to start green, then slowly get red, reaching completely red in (oh, say) 10 seconds. That time length is arbitrary though and I'd consider solutions that infinitely approach red. So my proposed pseudocode looks something like this:
Code:
//Get the amount of time between now and the last time it was updated
Timespan t = Datetime.Now - LastUpdate;
//Get the number of seconds that represents
int NumberOfSeconds = Convert.ToInt32(Timespan.Seconds);
//If the number is higher than 10, make it 10 (because we're not getting redder than red)
if (NumberOfSeconds > 10) NumberOfSeconds = 10;
//Return a color based on the number of seconds
switch
{
Case 1:
return Color.Green;
Case 2:
return Color.SomewhatLessGreen;
Case 3:
return Color.EvenLessGreen;
Case 4:
return Color.GreenWithSomePink;
Case 5:
return Color.HalfGreenHalfRed;
Case 6:
return Color.SomewhatMorePinkThanGreen;
Case 7:
return Color.EvenMoreRed;
Case 8:
return Color.FairlyRed;
Case 9:
return Color.AlmostCompletelyRed;
Case 10:
return Color.Red;
Case default:
return Color.Red;
}
So I have a method that words, but it's messy and ugly and hard to change/maintain... and I can't help the feeling that there's a MUCH better way to go about this. Anybody have a suggestion?
Thank you,
Dan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|