public void GreenToRed([Range(0, 255)] int time) { refColor = RgbColor.FromRgb(0, 255, 0); RgbColor newColor = animation.GetColor(StartTime, StartTime.AddMilliseconds(time), refColor); Assert.AreEqual(RgbColor.FromRgb(time, 255 - time, 0).ToString(), newColor.ToString()); }
protected bool CheckUsage() { if (IsInitialized) { int currentUsage = GetValue(); log.DebugFormat("{0} usage {1}%", GetTypeName(), currentUsage); if (this.Configuration == ConfigurationEnum.Alert) { if (this.TriggerType == TriggerTypeEnum.More && currentUsage > this.AlertPercent || this.TriggerType == TriggerTypeEnum.Less && currentUsage < this.AlertPercent) { log.Info("Trigger notification"); OnTriggered(String.Format("{0} usage at {1}%", GetTypeName(), currentUsage)); } } else if (this.Configuration == ConfigurationEnum.Monitor) { RgbColor c1; RgbColor c2; if (Pattern == null) { c1 = RgbColor.FromRgb(0, 255, 0); c2 = RgbColor.FromRgb(255, 0, 0); } else { if (Pattern.Animations.Count == 0) { c1 = RgbColor.FromRgb(0, 255, 0); c2 = RgbColor.FromRgb(255, 0, 0); } else if (Pattern.Animations.Count == 1) { c1 = RgbColor.FromRgb(0, 0, 0); c2 = Pattern.Animations[0].Color; } else { c1 = Pattern.Animations[0].Color; c2 = Pattern.Animations[1].Color; } } byte r = (byte)(c1.R + (c2.R - c1.R) / 100.0 * currentUsage); byte g = (byte)(c1.G + (c2.G - c1.G) / 100.0 * currentUsage); byte b = (byte)(c1.B + (c2.B - c1.B) / 100.0 * currentUsage); OnColorSend(r, g, b); } } return(true); }
public void BlueToGreen([Range(0, 255)] int time) { refColor = RgbColor.FromRgb(0, 0, 255); targetColor = RgbColor.FromRgb(0, 255, 0); animation.Color = targetColor; RgbColor newColor = animation.GetColor(StartTime, StartTime.AddMilliseconds(time), refColor); Assert.AreEqual(RgbColor.FromRgb(0, time, 255 - time).ToString(), newColor.ToString()); Assert.IsTrue(!animation.AnimationFinished); }
public void RedToBlue([Range(0, 255)] int time) { refColor = RgbColor.FromRgb(255, 0, 0); targetColor = RgbColor.FromRgb(0, 0, 255); animation.Color = targetColor; RgbColor newColor = animation.GetColor(StartTime, StartTime.AddMilliseconds(time), refColor); Assert.AreEqual(RgbColor.FromRgb(255 - time, 0, time).ToString(), newColor.ToString()); }
public RgbColor GetColorAt(int x, int y) { IntPtr desk = GetDesktopWindow(); IntPtr dc = GetWindowDC(desk); int a = (int)GetPixel(dc, x, y); ReleaseDC(desk, dc); System.Drawing.Color col = System.Drawing.Color.FromArgb(255, (a >> 0) & 0xff, (a >> 8) & 0xff, (a >> 16) & 0xff); return(RgbColor.FromRgb(col.R, col.G, col.B)); }
public void Init() { StartTime = DateTime.Now; animation = new Animation() { AnimationType = AnimationTypeEnum.Pulse, DurationPulse = 512 //Easier number for calculations }; targetColor = RgbColor.FromRgb(255, 0, 0); animation.Color = targetColor; }
public void Init() { StartTime = DateTime.Now; animation = new Animation() { AnimationType = AnimationTypeEnum.Blink, DurationBlink = 100 }; targetColor = RgbColor.FromRgb(255, 0, 0); animation.Color = targetColor; }
public RgbColor GetColor(CustomNotification notification) { int index = 0; int channel = 0; if (notification is DeviceNotification) { index = ((DeviceNotification)notification).LedFirstIndex * 3; channel = ((DeviceNotification)notification).GetValidChannel(); } return(RgbColor.FromRgb(LedFrame[channel][index + 1], LedFrame[channel][index], LedFrame[channel][index + 2])); }
public void Init() { StartTime = DateTime.Now; animation = new Animation() { AnimationType = AnimationTypeEnum.Morph, DurationMorph = 256 //Easier number for calculations }; targetColor = RgbColor.FromRgb(255, 0, 0); animation.Color = targetColor; refColor = RgbColor.FromRgb(0, 255, 0); }
public void TestFadeOut([Range(256, 511)] int time) { RgbColor newColor = animation.GetColor(StartTime, StartTime.AddMilliseconds(time)); Assert.AreEqual(RgbColor.FromRgb(511 - time, 0, 0).ToString(), newColor.ToString()); }
public void HalfBrightnessThreeQuarterWay() { RgbColor newColor = animation.GetColor(StartTime, StartTime.AddMilliseconds(animation.DurationPulse / 4 * 3)); Assert.AreEqual(RgbColor.FromRgb(127, 0, 0).ToString(), newColor.ToString()); }
public RgbColor GetColor(DateTime start, DateTime current, RgbColor refColor = null) { double fraction = 0; double frame = (current - start).TotalMilliseconds; switch (this.AnimationType) { case AnimationTypeEnum.SetColor: if (frame >= this.DelaySetColor) { this.AnimationFinished = true; frame = this.DelaySetColor; } break; case AnimationTypeEnum.Blink: if (frame >= this.DurationBlink * this.RepeatBlink) { this.AnimationFinished = true; frame = this.DurationBlink * this.RepeatBlink - 1; } if (frame % this.DurationBlink < this.DurationBlink / 2) { return(this.Color); } else { return(RgbColor.Black()); } case AnimationTypeEnum.Pulse: if (frame >= this.DurationPulse * this.RepeatPulse) { this.AnimationFinished = true; frame = this.DurationPulse * this.RepeatPulse; } fraction = frame % this.DurationPulse / this.DurationPulse; byte r; byte g; byte b; if (fraction <= 0.5) //Fade in { fraction = fraction * 2; r = (byte)Math.Ceiling(Color.R * fraction); g = (byte)Math.Ceiling(Color.G * fraction); b = (byte)Math.Ceiling(Color.B * fraction); } else //Fade out { fraction = 1 - (fraction - 0.5) * 2; r = (byte)Math.Floor(Color.R * fraction); g = (byte)Math.Floor(Color.G * fraction); b = (byte)Math.Floor(Color.B * fraction); } return(RgbColor.FromRgb(r, g, b)); case AnimationTypeEnum.Morph: if (refColor == null) { throw new ArgumentNullException("refColor", "Reference color is required for Morph animation"); } if (frame >= this.DurationMorph) { this.AnimationFinished = true; frame = this.DurationMorph; } fraction = frame / this.DurationMorph; if (Color.R > refColor.R) { r = (byte)Math.Ceiling(refColor.R + (Color.R - refColor.R) * fraction); } else { r = (byte)Math.Floor(refColor.R + (Color.R - refColor.R) * fraction); } if (Color.G > refColor.G) { g = (byte)Math.Ceiling(refColor.G + (Color.G - refColor.G) * fraction); } else { g = (byte)Math.Floor(refColor.G + (Color.G - refColor.G) * fraction); } if (Color.B > refColor.B) { b = (byte)Math.Ceiling(refColor.B + (Color.B - refColor.B) * fraction); } else { b = (byte)Math.Floor(refColor.B + (Color.B - refColor.B) * fraction); } return(RgbColor.FromRgb(r, g, b)); default: break; } return(this.Color); }
private void OnApplicationExit(object sender, EventArgs e) { color.rgb = RgbColor.FromRgb(0, 0, 0); stick.SetColor(color.rgb); Console.WriteLine("Exiting..."); }