public static IEnumerable <T> GetRainbow <T>(T start, int size, int hueStep = 50, int lightStep = 3, int satStep = 0) where T : IColorSpace, new() { Hsl next = start.To <Hsl>(); for (int i = 0; i < size; i++) { next = new Hsl { Ordinals = next.Ordinals }; next.H += hueStep; next.H %= 360; if (next.S + satStep > 100) { next.S = 20; } else { next.S += satStep; } if (next.L + lightStep > 80) { next.L = 20; } else { next.L += lightStep; } yield return(next.To <T>()); } }
public CubeHelix(Hsl colorARgb, Hsl colorBRgb, double gamma = 1.0) { this.Gamma = gamma; this.colorA = colorARgb.To <Hsl>(); this.colorB = colorBRgb.To <Hsl>(); this.aHue = (this.colorA.H + 120) * Radians; this.bHue = ((this.colorB.H + 120) * Radians) - this.aHue; this.aSaturation = this.colorA.S; this.bSaturation = this.colorB.S - this.aSaturation; this.aLuminosity = this.colorA.L; this.bLuminosity = this.colorB.L - this.aLuminosity; if (double.IsNaN(this.bSaturation)) { this.bSaturation = 0; if (double.IsNaN(this.aSaturation)) { this.aSaturation = this.colorB.S; } } if (double.IsNaN(this.bHue)) { this.bHue = 0; if (double.IsNaN(this.aHue)) { this.aHue = this.colorB.H; } } }
public static Color HslToRgb(double h, double s, double l) { var hsl = new Hsl { H = h, S = s, L = l }; var r = hsl.To <Rgb>(); var d = Color.FromArgb((int)r.R, (int)r.G, (int)r.B); return(d); }
public static void DrawCommunities(List <List <Point> > lp, string filename, string prefix) { Bitmap img = new Bitmap(filename); Bitmap bm = new Bitmap(img); lp = lp.OrderBy(x => x.OrderBy(y => y.x).First().x).ToList(); int index = 0; Random r = new Random(1); var colors = Enumerable.Range(0, 360).Where((x, i) => i % 30 == 0).ToList(); var colors2 = colors.Select(x => new Hsl { H = x, S = 100, L = 50 }).ToList(); var colors3 = new List <Hsl> { new Hsl { H = 0, S = 100, L = 50 }, new Hsl { H = 233, S = 100, L = 50 } }; //colors2.Insert(0, new Hsl { H = 0, S = 100, L = 0 }); foreach (var community in lp) { //var value = new Hsl { H = r.Next(0, 360), S = r.Next(50, 100), L = r.Next(40, 60) }; //var value = colors2[index]; Hsl value = null; try { value = colors3[lp.IndexOf(community)]; } catch (Exception e) { value = new Hsl { H = r.Next(0, 360), S = r.Next(50, 100), L = r.Next(40, 60) }; } //var value = colors2[lp.IndexOf(community)]; var rgb = value.To <Rgb>(); Color c = Color.FromArgb(255, (int)rgb.R, (int)rgb.G, (int)rgb.B); foreach (var v in community) { bm.SetPixel((int)v.x, (int)v.y, c); } index += 1; } bm.Save(Path.Combine("output2", Path.GetFileNameWithoutExtension(filename) + "_" + prefix + "_bm.png")); }
public Task <CommandResponse> SetColorFromHSL(Hsl hsl) { Hsv hsv = hsl.To <Hsv>(); Commands commands = new Commands(); commands.AddCommand("work_mode", "colour"); commands.AddCommand("colour_data_v2", new { h = Math.Round(hsv.H), s = Math.Round(hsv.S * 1000), v = Math.Round(hsv.V * 1000) }); return(rumahTuya.SendCommands(deviceId, commands)); }
public ColorPicker(Color color) { InitializeMoreComponents(); InitializeComponent(); //float[] col = new float[] { color.GetHue(), color.GetSaturation(), color.GetBrightness() }; Hsl hsl = new Hsl() { H = color.GetHue(), S = color.GetSaturation() * 100, L = color.GetBrightness() * 100 }; Hsv hsv = hsl.To <Hsv>(); _selectedColor = new HSVColor(hsv); InvalidatePanels(); }
public Color setColor(int h) { double stat = Convert.ToDouble(h); if (stat > 360) { stat = 360;//If pokemon stat is over 360, set it to 360. The highest hue number is 360. This shouldn't occur since the largest pokemon stat is 255 } stat = convertMaxNumber(stat);//convert to porportional number var myHSL = new Hsl { H = stat, S = 100, L = 65 }; //the hue determines the color(S and L always stay the same), goes from red -> light blue as number increases. You need colormine nuget for this to work. var myRGB = myHSL.To <Rgb>(); //converts HSL to RGB. Color myRgbColor = new Color(); myRgbColor = Color.FromArgb(255, Convert.ToInt16(myRGB.R), Convert.ToInt16(myRGB.G), Convert.ToInt16(myRGB.B));//set color object. The 255 is aplha and set the color to a visible color. return(myRgbColor); }