private System.Windows.Media.Color GetMidBrightColor() { HSB hsb = new HSB(_colour.HSB.Hue, _colour.HSB.Saturation, 0.5f); RGB rgb = hsb.GetRGB(); return(System.Windows.Media.Color.FromRgb(rgb.R, rgb.G, rgb.B)); }
public async Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken) { var r = new Random(); var center = EffectSettings.LocationCenter; var orderedLayer = layer.OrderByDescending(x => x.LightLocation.Angle(center.X, center.Y)); var hsb = r.Next(HSB.HueMaxValue); for (int i = 0; i < Chunks; i++) { var hsbColor = new HSB(hsb, 255, 255); _colors.Add(hsbColor.GetRGB()); hsb += (HSB.HueMaxValue / Chunks); } while (!cancellationToken.IsCancellationRequested) { foreach (var light in orderedLayer) { var angle = light.LightLocation.Angle(center.X, center.Y).Move360(StartRotation); double normalAngle = WrapValue(360, (int)angle); int arrayIndex = (int)(normalAngle / 361 * Chunks); light.SetState(cancellationToken, _colors[arrayIndex], 1); } StartRotation += AddRotation; StartRotation = WrapValue(360, StartRotation); await Task.Delay(waitTime() / 6); } }
public async Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken) { var r = new Random(); var center = EffectSettings.LocationCenter; var orderedLayer = layer.OrderByDescending(x => x.LightLocation.Angle(center.X, center.Y)); while (!cancellationToken.IsCancellationRequested) { foreach (var light in orderedLayer) { Task.Run(async() => { var distance = 1 + light.LightLocation.Y; var timeSpan = waitTime() / 2 * distance; var addHue = (int)(Steps / 2 * distance); await Task.Delay(timeSpan); //Debug.WriteLine($"{light.Id} Angle {angle} and timespan {timeSpan.TotalMilliseconds}"); var hsbColor = new HSB(StartStep + addHue, 255, 255); light.SetState(cancellationToken, hsbColor.GetRGB(), 1, waitTime() / 2); if (DipToBlack) { await Task.Delay(waitTime() * 0.8); light.SetBrightness(cancellationToken, 0, waitTime() * 0.1); } }); } StartStep += Steps; await Task.Delay(waitTime() * 1.1); } }
public static RGBColor ToRgb(this State state) { HSB hsb = new HSB(); hsb.Brightness = state.Brightness; if (state.Hue.HasValue) hsb.Hue = state.Hue.Value; if (state.Saturation.HasValue) hsb.Saturation = state.Saturation.Value; return hsb.GetRGB(); }
public static async Task SendCommandA(BeatmapEventData data, HSB hsbColor, double brightness, HSB inithsbColor, HSB endhsbColor, double time, bool gradient) { CancellationToken token = LightInfo.token; EntertainmentLayer entLayer = LightInfo.layer; if (gradient == true) { switch (data.value) { case 0: entLayer.SetState(token, null, brightness); break; case 1: entLayer.SetState(token, inithsbColor.GetRGB(), 1); await Task.Delay(TimeSpan.FromMilliseconds(20), token); entLayer.SetState(token, endhsbColor.GetRGB(), 1, TimeSpan.FromSeconds(time)); break; case 5: entLayer.SetState(token, inithsbColor.GetRGB(), 1); await Task.Delay(TimeSpan.FromMilliseconds(20), token); entLayer.SetState(token, endhsbColor.GetRGB(), 1, TimeSpan.FromSeconds(time)); break; } } else { switch (data.value) { case 0: entLayer.SetState(token, null, brightness); break; case 1: entLayer.SetState(token, hsbColor.GetRGB(), 1); break; case 2: entLayer.SetState(token, hsbColor.GetRGB(), 1); await Task.Delay(TimeSpan.FromMilliseconds(20), token); entLayer.SetState(token, hsbColor.GetRGB(), brightness, TimeSpan.FromSeconds(1)); break; case 3: entLayer.SetState(token, hsbColor.GetRGB(), 1); await Task.Delay(TimeSpan.FromMilliseconds(20), token); entLayer.SetState(token, hsbColor.GetRGB(), brightness, TimeSpan.FromSeconds(1)); break; case 5: entLayer.SetState(token, hsbColor.GetRGB(), 1); break; case 6: entLayer.SetState(token, hsbColor.GetRGB(), 1); await Task.Delay(TimeSpan.FromMilliseconds(20), token); entLayer.SetState(token, hsbColor.GetRGB(), brightness, TimeSpan.FromSeconds(1)); break; case 7: entLayer.SetState(token, hsbColor.GetRGB(), 1); await Task.Delay(TimeSpan.FromMilliseconds(20), token); entLayer.SetState(token, hsbColor.GetRGB(), brightness, TimeSpan.FromSeconds(1)); break; } } }
public async Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken) { HSB hsb = new HSB(0, 255, 255); while (!cancellationToken.IsCancellationRequested) { layer.SetState(cancellationToken, hsb.GetRGB(), 1); await Task.Delay(waitTime() / 10); hsb.Hue += 100; if (hsb.Hue >= HSB.HueMaxValue) { hsb.Hue = 0; } } }
public async Task Start(EntertainmentLayer layer, Func <TimeSpan> waitTime, RGBColor?color, CancellationToken cancellationToken) { Random r = new Random(); while (!cancellationToken.IsCancellationRequested) { var nextcolor = color ?? RGBColor.Random(); var hsb = nextcolor.GetHSB(); foreach (var light in layer) { var addHue = r.Next(-6000, 6000); var addBri = r.Next(-100, 100); var randomHsb = new HSB(hsb.Hue + addHue, hsb.Saturation, WrapValue(255, hsb.Brightness + addBri)); light.SetState(cancellationToken, randomHsb.GetRGB(), 1, UseTransition ? waitTime() / 2 : TimeSpan.Zero); } await Task.Delay(waitTime()); } }
/// <summary> /// Create a hue bitmap. Used to fabricate the png files used in the LightControl. I left it /// in, so you can generate new files easily (with different dimensions if you wish). /// </summary> public static void PaintHue() { Bitmap bmp = new Bitmap(290, 25); Graphics gr = Graphics.FromImage(bmp); RGBColor rgbC = new RGBColor(0, 0, 0); HSB hsb = new HSB(0, 255, 255); Color c; int hue; for (int h = 0; h < bmp.Width; h++) { hue = (int)(HSB.HueMaxValue * 1.0 * h / bmp.Width); hsb.Hue = hue; rgbC = hsb.GetRGB(); c = fromRGB(rgbC); using (Pen p = new Pen(c)) gr.DrawLine(p, h, 0, h, bmp.Height); } bmp.Save("hue.png"); }
private RGBColor ClampBrightness(string colorString, LightData lightData, int brightness) { var oColor = new RGBColor(colorString); // Clamp our brightness based on settings long bClamp = 255 * brightness / 100; if (lightData.OverrideBrightness) { var newB = lightData.Brightness; bClamp = 255 * newB / 100; } var hsb = new HSB((int)oColor.GetHue(), (int)oColor.GetSaturation(), (int)oColor.GetBrightness()); if (hsb.Brightness > bClamp) { hsb.Brightness = (int)bClamp; } oColor = hsb.GetRGB(); return(oColor); }
static void Main(string[] args) { #region Startup var versionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location); var attribute = Assembly.GetExecutingAssembly() .GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false) .Cast <AssemblyDescriptionAttribute>().FirstOrDefault(); var appName = string.Format("{0} v{1}", typeof(Program).Assembly.GetName().Name, versionInfo.ProductVersion); Console.Title = appName; Console.WindowWidth = 81; Console.BufferWidth = 81; Console.WindowHeight = 36; Console.WriteLine(); Console.BackgroundColor = ConsoleColor.Gray; Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(appName); Console.ResetColor(); if (attribute != null) { Console.WriteLine(attribute.Description); } Console.WriteLine(); Console.WriteLine(versionInfo.LegalCopyright); Console.WriteLine(String.Empty.PadLeft(80, '-')); Console.WriteLine(); #endregion Start: Console.WriteLine("Converters:"); Console.WriteLine("1. RGB hexvalue to HSB (hue, sat, bri)"); Console.WriteLine("2. RGB (red, green, blue) to HSB (hue, sat, bri)"); Console.WriteLine("3. HSB (hue, sat, bri) to RGB hexvalue"); Console.WriteLine(); Console.Write("Enter number of converter you wan't to use: "); var converterSelection = Console.ReadKey(); Console.WriteLine(); Console.WriteLine(String.Empty.PadLeft(80, '-')); Console.WriteLine(); switch (converterSelection.KeyChar) { case '1': Console.WriteLine("Convert RGB hexvalue to HSB (hue, sat, bri)"); Console.WriteLine(String.Empty.PadLeft(80, '-')); Console.WriteLine("Enter RGB hexcode (6 digits):"); Console.Write("#"); var input = Console.ReadLine(); Console.WriteLine(); var rgbInput = new RGBColor(); try { rgbInput = new RGBColor(input); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Invalid input!"); Console.WriteLine(ex.Message); Console.ReadKey(); return; } var hsb = rgbInput.GetHSB(); Console.WriteLine("Hue: {0}", hsb.Hue); Console.WriteLine("Sat: {0}", hsb.Saturation); Console.WriteLine("Bri: {0}", hsb.Brightness); break; case '2': Console.WriteLine("Convert RGB (red, green, blue) to HSB (hue, sat, bri)"); Console.WriteLine(String.Empty.PadLeft(80, '-')); Console.WriteLine("Enter the RGB values (0-255):"); Console.Write("R: "); var r = Console.ReadLine().ToByte(); Console.Write("G: "); var g = Console.ReadLine().ToByte(); Console.Write("B: "); var b = Console.ReadLine().ToByte(); Console.WriteLine(); var rgbInput2 = new RGBColor(r, g, b); var hsb2 = rgbInput2.GetHSB(); Console.WriteLine("Hue: {0}", hsb2.Hue); Console.WriteLine("Sat: {0}", hsb2.Saturation); Console.WriteLine("Bri: {0}", hsb2.Brightness); break; case '3': Console.WriteLine("Convert HSB (hue, sat, bri) to RGB hexvalue"); Console.WriteLine(String.Empty.PadLeft(80, '-')); Console.WriteLine("Enter the HSB values:"); Console.Write("Hue: "); var hue = Console.ReadLine().ToUInt16(); //This is a wrapping value between 0 and 65535 Console.Write("Sat: "); var sat = Console.ReadLine().ToByte(); Console.Write("Bri: "); var bri = Console.ReadLine().ToByte(); Console.WriteLine(); var hsbInput = new HSB(hue, sat, bri); Console.WriteLine("RGB: #{0}", hsbInput.GetRGB().ToHex()); break; default: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Invalid input!"); break; } Console.WriteLine(); Console.WriteLine(String.Empty.PadLeft(80, '-')); Console.Write("Press [Space] for next conversion or any key for exit "); switch (Console.ReadKey().Key) { case ConsoleKey.Spacebar: Console.WriteLine(); Console.WriteLine(); goto Start; default: return; } }
public static RGBColor ToRgb(this State state) { HSB hsb = new HSB(state.Hue ?? 0, state.Saturation ?? 0, state.Brightness); return(hsb.GetRGB()); }