void AnimateCycleRandomColors (object sender) { Random r = new Random(); HSLColor targetColor = new HSLColor(RgbColor.FromRgb(r.Next(256), r.Next(256), r.Next(256))); targetColor.Lightness = 0.5; RgbColor currentColor = RgbColor.FromRgb(0, 0, 0); FadeMode = FadeModeEnum.FadeOut; while (!((BackgroundWorker)sender).CancellationPending) { if (targetColor.Color.R == currentColor.R && targetColor.Color.G == currentColor.G && targetColor.Color.B == currentColor.B) { WaitSeconds(ColorDisplayTime); targetColor = new HSLColor(RgbColor.FromRgb(r.Next(256), r.Next(256), r.Next(256))); //drop down lightness to see nicer and more rich colors targetColor.Lightness = 0.5; } else { currentColor.R += (byte)Math.Sign(targetColor.Color.R - currentColor.R); currentColor.G += (byte)Math.Sign(targetColor.Color.G - currentColor.G); currentColor.B += (byte)Math.Sign(targetColor.Color.B - currentColor.B); SendColor(currentColor); Thread.Sleep(10); } } }
void AnimatePulsateSingleColor (object sender) { HSLColor currentColor = new HSLColor(TargetColor); double targetLightness = currentColor.Lightness; currentColor.Lightness = 0; FadeMode = FadeModeEnum.FadeIn; int pulseCount = 0; while (!((BackgroundWorker)sender).CancellationPending) { if (FadeMode == FadeModeEnum.FadeIn) { if (currentColor.Lightness >= targetLightness) { //fade out FadeMode = FadeModeEnum.FadeOut; } else { currentColor.Lightness += AnimationSpeed; Thread.Sleep(5); SendColor(currentColor.Color); } } else { if (currentColor.Lightness <= 0) { FadeMode = FadeModeEnum.FadeIn; pulseCount++; if (pulseCount >= TargetPulses) { break; } } else { currentColor.Lightness -= AnimationSpeed; Thread.Sleep(5); SendColor(currentColor.Color); } } } }
void AnimatePulsateRandomColors (object sender) { Random r = new Random(); HSLColor targetColor = new HSLColor(RgbColor.FromRgb(r.Next(256), r.Next(256), r.Next(256))); HSLColor currentColor = new HSLColor(RgbColor.FromRgb(0, 0, 0)); FadeMode = FadeModeEnum.FadeOut; while (!((BackgroundWorker)sender).CancellationPending) { if (FadeMode == FadeModeEnum.FadeIn) { if (currentColor.Lightness >= 0.5 || currentColor.Lightness >= targetColor.Lightness) { //fade out FadeMode = FadeModeEnum.FadeOut; WaitSeconds(ColorDisplayTime); } else { currentColor.Lightness += 0.01; Thread.Sleep(30); SendColor(currentColor.Color); } } else { if (currentColor.Lightness <= 0) { targetColor = new HSLColor(RgbColor.FromRgb(r.Next(256), r.Next(256), r.Next(256))); currentColor = targetColor; //drop down lightness to see nicer and more rich colors currentColor.Lightness = 0.0; FadeMode = FadeModeEnum.FadeIn; } else { currentColor.Lightness -= 0.01; Thread.Sleep(30); SendColor(currentColor.Color); } } } }