public static Colors ColorTransition(Bulb bulb, Colors openColor, Colors closeColor, int delay, double resolution, double luminocity) { Colors currentColor = new Colors(); double currentRatio = 0; while (true) { Thread.Sleep(delay); currentColor.Red = (byte)Math.Abs((currentRatio * closeColor.Red) + ((1 - currentRatio) * openColor.Red)); currentColor.Green = (byte)Math.Abs((currentRatio * closeColor.Green) + ((1 - currentRatio) * openColor.Green)); currentColor.Blue = (byte)Math.Abs((currentRatio * closeColor.Blue) + ((1 - currentRatio) * openColor.Blue)); currentColor.WarmWhite = (byte)Math.Abs((currentRatio * closeColor.WarmWhite) + ((1 - currentRatio) * openColor.WarmWhite)); currentColor.ColdWhite = (byte)Math.Abs((currentRatio * closeColor.ColdWhite) + ((1 - currentRatio) * openColor.ColdWhite)); if (currentRatio < 1) { bulb.SetColorAndWhiteLevel(SetLuminocity(currentColor, LuminocityClamp(luminocity))); currentRatio = Math.Clamp(currentRatio + resolution, 0.0, 1.0); } else { Thread.Sleep(20); bulb.SetColorAndWhiteLevel(SetLuminocity(currentColor, LuminocityClamp(luminocity))); break; } } return(bulb.Colors); }
public static Colors Flash(Bulb bulb, Colors color, int delay, double startLuminocity, double endLuminocity) { startLuminocity = Math.Clamp(startLuminocity, 0.0, 1.0); endLuminocity = Math.Clamp(endLuminocity, 0.0, 1.0); double currentLuminocity = startLuminocity; while (true) { Thread.Sleep(delay); if (startLuminocity < endLuminocity && currentLuminocity < endLuminocity) { currentLuminocity += .01; } else if (startLuminocity > endLuminocity && currentLuminocity > endLuminocity) { currentLuminocity -= .01; } else { Thread.Sleep(20); bulb.SetColorAndWhiteLevel(SetLuminocity(color, LuminocityClamp(endLuminocity))); return(bulb.Colors); } bulb.SetColorAndWhiteLevel(SetLuminocity(color, LuminocityClamp(currentLuminocity))); } }
public static void Lantern(Bulb bulb) { bulb.SetColorAndWhiteLevel(0, 0, 0, 0, 0); Colors randomBlue = new Colors(RandomNumber((byte)0, (byte)20), RandomNumber((byte)0, (byte)255), RandomNumber((byte)50, (byte)255), 0, 0); Colors randomPink = new Colors(255, 0, RandomNumber((byte)5, (byte)220), 0, 0); int DelayBetweenPulses = RandomNumber(1000, 5000), openDelaySpeed = RandomNumber(10, 20), closeDelaySpeed = RandomNumber(1, 10); Thread.Sleep(DelayBetweenPulses); int randomChance = RandomNumber((int)0, (int)2); Console.WriteLine(randomChance); if (randomChance == 1) { Console.WriteLine(randomChance); Flash(bulb, randomBlue, openDelaySpeed, 0, 1.0); Flash(bulb, randomBlue, closeDelaySpeed, 1.0, 0); } else { Flash(bulb, randomPink, openDelaySpeed, 0, 1.0); Flash(bulb, randomPink, closeDelaySpeed, 1.0, 0); } }
public static void Lightning(Bulb bulb) { bulb.SetColorAndWhiteLevel(0, 0, 0, 0, 0); Thread.Sleep(RandomNumber(5000, 50000)); bulb.SetColdWhiteLevel(RandomNumber((byte)100, (byte)255)); Thread.Sleep(RandomNumber(10, 100)); bulb.SetColorAndWhiteLevel(0, 0, 0, 0, 0); Thread.Sleep(25); int randomChance = RandomNumber(1, 3); if (randomChance == 3) { bulb.SetColdWhiteLevel(RandomNumber((byte)100, (byte)255)); } }