// Could have been a dependency property that pieces of the UI bind to, but the interaction is complex enough // to make this the easier route: public void SetCurrentColor(HSVColor value) { this.currentColor = value; Color rgbColor = ColorConverter.HSVToRGB(value); this.ResetButton.IsEnabled = true; this.PreviewTile.Fill = new SolidColorBrush(rgbColor); // Only update the TextBox if this isn't being done in response to typing. That prevents // text like "red" from changing to "#FF0000" and prevents the cursor from jumping to the beginning. if (!keyPressed) this.ColorTextBox.Text = value.ToString(); this.HueGradientStop.Color = ColorConverter.HSVToRGB(new HSVColor { A = 255, H = value.H, S = 1, V = 1 }); Canvas.SetLeft(this.HueThumb, (value.H / 360) * this.HueSlider.Width - this.HueThumb.Width / 2); // Update AlphaSlider and AlphaThumb: Color opaqueColor = rgbColor; opaqueColor.A = 255; Color transparentColor = rgbColor; transparentColor.A = 0; this.alphaGradientStop.Color = opaqueColor; this.alphaGradientStop2.Color = transparentColor; Canvas.SetLeft(this.AlphaThumb, ((double)value.A / 255) * this.AlphaSlider.Width - this.AlphaThumb.Width / 2); // Update SaturationValueMap: Point saturationValuePoint = new Point(value.S * this.SaturationValueMap.Width, value.V * this.SaturationValueMap.Height); this.SelectionLineX1.X1 = this.SelectionLineX1.X2 = saturationValuePoint.X; this.SelectionLineX2.X1 = this.SelectionLineX2.X2 = saturationValuePoint.X; this.SelectionLineY1.Y1 = this.SelectionLineY1.Y2 = saturationValuePoint.Y; this.SelectionLineY2.Y1 = this.SelectionLineY2.Y2 = saturationValuePoint.Y; }
public static Color ToRGB(HSVColor hsv) { float r = hsv.h; float g = hsv.h; float b = hsv.h; if (hsv.s != 0) { float max = hsv.v; float diff = hsv.v * hsv.s; float min = hsv.v - diff; float h = hsv.h * 360.0f; if (h < 60.0f * 1) { r = max; g = h * diff / 60.0f + min; b = min; } else if (h < 60.0f * 2) { r = -(h - 120.0f) * diff / 60.0f + min; g = max; b = min; } else if (h < 60.0f * 3) { r = min; g = max; b = +(h - 120.0f) * diff / 60.0f + min; } else if (h < 60.0f * 4) { r = min; g = -(h - 240.0f) * diff / 60.0f + min; b = max; } else if (h < 60.0f * 5) { r = +(h - 240.0f) * diff / 60.0f + min; g = min; b = max; } else if (h <= 60.0f * 6) { r = max; g = min; b = -(h - 360.0f) * diff / 60.0f + min; } else { r = 0; g = 0; b = 0; } } return new Color(Mathf.Clamp01(r), Mathf.Clamp01(g), Mathf.Clamp01(b), hsv.a); }
public ViewModel() { // Set default colour to white, full brightness rgbColor = new RGBColor(1.0f, 1.0f, 1.0f); hsvColor = new HSVColor(0.0f, 0.0f, 1.0f); temperature = ColorTemperature.Neutral; brightness = 1.0f; ColorChanged(); }
public void HoldColor(HSVColor color, LightZone zones, float duration, bool priority = false) { int frames = (int)Math.Round(duration * FPS); for (int i = 0; i < frames; i++) { LEDData data = LEDData.Empty; ApplyColorToZones(data, zones, color); SendFrame(data, zones, priority); } }
public ColorScale(Color min, Color max, float minValue, float maxValue) { if (minValue >= maxValue) { throw new System.Exception("invalid parameters"); } this.min = new HSVColor(min); this.max = new HSVColor(max); this.minValue = minValue; this.maxValue = maxValue; }
private void OnCastE() { Task.Run(async() => { await Task.Delay(1000); if (!rCastInProgress) { _ = animator.ColorBurst(HSVColor.FromRGB(229, 115, 255), 0.15f); } }); }
private IEnumerator WhileTimerTicking() { // Update the interface while the timer is going. while (true) { clockText.text = string.Format(secondsFormat, drivingTimer.RemainingSeconds); radialFillImage.fillAmount = 1 - drivingTimer.Interpolant; radialFillImage.color = HSVColor.Lerp(filledColor, emptyColor, drivingTimer.Interpolant).AsRGB; yield return(null); } }
public static HSVColor ConvertRGBToHSV(double r, double b, double g) { double delta, min; double h = 0, s, v; min = Math.Min(Math.Min(r, g), b); v = Math.Max(Math.Max(r, g), b); delta = v - min; if (v.Equals(0)) { s = 0; } else { s = delta / v; } if (s.Equals(0)) { h = 360; } else { if (r.Equals(v)) { h = (g - b) / delta; } else if (g.Equals(v)) { h = 2 + (b - r) / delta; } else if (b.Equals(v)) { h = 4 + (r - g) / delta; } h *= 60; if (h <= 0.0) { h += 360; } } HSVColor hsvColor = new HSVColor { H = 360 - h, S = s, V = v / 255 }; return(hsvColor); }
//No need to test other values, because Unity's h values are only defined from [0, 1) public void GetNew_Test(float value) { // setup float expected = value; HSVColor hsvColor = new HSVColor(Color.blue); // perform hsvColor = hsvColor.GetNew(value); // assert Assert.AreEqual(value, (float)Math.Round(hsvColor.h, 1)); }
bool Match(HSVColor ex, double hd, double sd, HSVColor test) { if (Math.Abs(ex.H - test.H) > hd) { return(false); } double ss = ex.S - test.S; double vv = ex.V - test.V; double svdist = Math.Sqrt(ss * ss + vv * vv); return(svdist <= sd); }
List <string> colorValue(HSVColor hsvColor, ColorModel colorModel) { Color color = hsvColor.toColor(); if (colorModel == ColorModel.hex) { return(new List <string>() { color.red.ToString("X2"), color.green.ToString("X2"), color.blue.ToString("X2"), $"{(color.opacity * 100).round()}%" }); } else if (colorModel == ColorModel.rgb) { return(new List <string>() { color.red.ToString(), color.green.ToString(), color.blue.ToString(), $"{(color.opacity * 100).round()}%" }); } else if (colorModel == ColorModel.hsv) { return(new List <string>() { $"{hsvColor.hue.round()}°", $"{(hsvColor.saturation * 100).round()}%", $"{(hsvColor.value * 100).round()}%", $"{(hsvColor.alpha * 100).round()}%", }); } else if (colorModel == ColorModel.hsl) { HSLColor hslColor = Utils.hsvToHsl(hsvColor); return(new List <string>() { $"{hslColor.hue.round()}°", $"{(hslColor.saturation * 100).round()}%", $"{(hslColor.lightness * 100).round()}%", $"{(hslColor.alpha * 100).round()}%", }); } else { return(new List <string>() { "??", "??", "??", "??" }); } }
public static HSVColor GetColorFromJsonClass(JSONClass colorObject) { var h = LoadFloatFromJsonFloatProperty(colorObject, "h", 0); var s = LoadFloatFromJsonFloatProperty(colorObject, "s", 0); var v = LoadFloatFromJsonFloatProperty(colorObject, "v", 0); var newColor = new HSVColor(); newColor.H = h ?? 0; newColor.S = s ?? 0; newColor.V = v ?? 0; return(newColor); }
public void TestSClamping_validValue() { HSVColor actual = new HSVColor(0.5f, 0.5f, 0.5f); actual.Saturation = 0.7f; HSVColor expected = new HSVColor(0.5f, 0.7f, 0.5f); Assert.That(actual.Hue, Is.EqualTo(expected.Hue)); Assert.That(actual.Saturation, Is.EqualTo(expected.Saturation)); Assert.That(actual.Value, Is.EqualTo(expected.Value)); }
public void TestHClamping_TooHighValue() { HSVColor actual = new HSVColor(0.5f, 0.5f, 0.5f); actual.Hue = 2.7f; HSVColor expected = new HSVColor(1.0f, 0.5f, 0.5f); Assert.That(actual.Hue, Is.EqualTo(expected.Hue)); Assert.That(actual.Saturation, Is.EqualTo(expected.Saturation)); Assert.That(actual.Value, Is.EqualTo(expected.Value)); }
public Widget colorPickerSlider(TrackType trackType) { return(new ColorPickerSlider( trackType, currentHsvColor, (HSVColor color) => { setState(() => { currentHsvColor = color; }); widget.onColorChanged(currentHsvColor); }, displayThumbColor: widget.displayThumbColor )); }
public Led[] DoFrame() // TODO: Latency issues... { leds.FadeToBlackAllLeds(0.3f); // 0.3f * delta que es 20 ms se supone if (!newAudioAvailable) { return(this.leds); } newAudioAvailable = false; var y_in = FFTUtil.ProcessAudio(audio); if (y_in.Length < this.lastIndex) { return(this.leds); } var y = new double[this.lastIndex]; Array.Copy(y_in, 0, y, 0, this.lastIndex); y = y.Select(x => x < 0 ? 0 : x).ToArray(); double[] y_scaled = new double[this.lastIndex]; for (int i = 0; i < this.lastIndex; i++) { var freq = FFTUtil.GetFreqForIndex(i, FFT_SPACING_HZ); var val = y[i]; double scaled; if (freq <= BASS_MAX_FREQ) { scaled = Utils.Scale(val, 0, BASS_TOP_LIMIT, 0, 1); } else { scaled = Utils.Scale(val, 0, MID_TOP_LIMIT, 0, 1); } y_scaled[i] = scaled; } HSVColor[] yColors = new HSVColor[this.lastIndex]; for (int i = 0; i < this.lastIndex; i++) { yColors[i] = UtilsLED.ValueToHSV(this.ledCount / 2, this.freqArray[i], y_scaled[i]); } for (int i = 0; i < this.lastIndex; i++) { if (this.freqArray[i] == this.ledCount / 2) { break; } leds.AddSymmetricColorAroundLeds(this.freqArray[i], yColors[i]); } return(this.leds); }
public static HSVColor RGBToHSV(Color color) { HSVColor ret = new HSVColor(0f, 0f, 0f, color.a); float r = color.r; float g = color.g; float v = color.b; float max = Mathf.Max(r, Mathf.Max(g, v)); if (max <= 0f) { return(ret); } float min = Mathf.Min(r, Mathf.Min(g, v)); float dif = max - min; if (max > min) { if (WadeUtils.AreEqual(g, max)) { ret.h = (v - r) / dif * 60f + 120f; } else if (WadeUtils.AreEqual(v, max)) { ret.h = (r - g) / dif * 60f + 240f; } else if (v > g) { ret.h = (g - v) / dif * 60f + 360f; } else { ret.h = (g - v) / dif * 60f; } if (WadeUtils.IsNegative(ret.h)) { ret.h = ret.h + 360f; } } else { ret.h = 0f; } ret.h *= 1f / 360f; ret.s = (dif / max) * 1f; ret.v = max; return(ret); }
private void ApplyColorToZones(LEDData frameData, LightZone zones, HSVColor color) { List <Led[]> colArrays = frameData.GetArraysForZones(zones); foreach (Led[] arr in colArrays) { foreach (Led l in arr) { l.Color(color); } } }
protected void SetupPluginUI() { List <string> choices = new List <string>(); choices.Add("None"); choices.Add("FPS"); choices.Add("Load Dir"); choices.Add("Total Atoms"); JSONStorableStringChooser jsonTypeTopLeft = new JSONStorableStringChooser("TopLeft", choices, typeTopLeft, "Top Left", SetTopLeft); UIDynamicPopup dropdownTopLeft = CreatePopup(jsonTypeTopLeft); dropdownTopLeft.labelWidth = 300f; JSONStorableStringChooser jsonTypeTopRight = new JSONStorableStringChooser("TopRight", choices, typeTopRight, "Top Right", SetTopRight); UIDynamicPopup dropdownTopRight = CreatePopup(jsonTypeTopRight, true); dropdownTopRight.labelWidth = 300f; JSONStorableStringChooser jsonTypeBottomLeft = new JSONStorableStringChooser("BottomLeft", choices, typeBottomLeft, "Bottom Left", SetBottomLeft); UIDynamicPopup dropdownBottomLeft = CreatePopup(jsonTypeBottomLeft); dropdownBottomLeft.labelWidth = 300f; JSONStorableStringChooser jsonTypeBottomRight = new JSONStorableStringChooser("BottomRight", choices, typeBottomRight, "Bottom Right", SetBottomRight); UIDynamicPopup dropdownBottomRight = CreatePopup(jsonTypeBottomRight, true); dropdownBottomRight.labelWidth = 300f; // let user adjust scale and top for HMD viewport differences and personal preference. JSONStorableFloat jsonTopOffset = new JSONStorableFloat("Top Offset", topOffset, SetTopOffset, -2f, +2f, true); RegisterFloat(jsonTopOffset); sliderTopOffset = CreateSlider(jsonTopOffset); JSONStorableFloat jsonScale = new JSONStorableFloat("HUD Scale", hudScale, SetScale, 10f, 200f, true); RegisterFloat(jsonScale); sliderScale = CreateSlider(jsonScale); JSONStorableFloat jsonFontSize = new JSONStorableFloat("Text Size", fontSize, SetFontSize, 10f, 100f, true); RegisterFloat(jsonFontSize); sliderFontSize = CreateSlider(jsonFontSize); // JSONStorableColor example HSVColor hsvc = HSVColorPicker.RGBToHSV(textColor.r, textColor.g, textColor.b); JSONStorableColor jsonTextColor = new JSONStorableColor("Text Color", hsvc, SetTextColor); RegisterColor(jsonTextColor); CreateColorPicker(jsonTextColor, true); }
public HSVColorBuffer(int width, int height, Color[] colorData) { this.width = width; this.height = height; this.data = new HSVColor[colorData.Length]; for (int i = 0; i < colorData.Length; i++) { this.data[i] = HSVColor.FromColor(colorData[i]); } }
public static Animation LoadFromFile(string path) { string text = ""; try { text = File.ReadAllText(path); } catch (Exception e) { Debug.WriteLine(e.StackTrace); throw new ArgumentException("File does not exist.", e); } try { string[] lines = text.Split('\n'); string[] data = lines[0].Split(','); int numLeds = int.Parse(data[0]); int numFrames = int.Parse(data[1]); string animationData = ""; if (lines.Length > 2) { // multiline format for (int i = 1; i <= numFrames; i++) { lines[i] = lines[i].Replace("\r", ""); lines[i] = lines[i].Replace("\n", ","); animationData += lines[i]; } } else { animationData = lines[1]; } string[] bytes = animationData.Split(','); List <HSVColor[]> animation = new List <HSVColor[]>(); for (int i = 0; i < numFrames; i++) { animation.Add(new HSVColor[numLeds]); for (int j = 0; j < numLeds; j++) { Color rgb = Color.FromArgb(int.Parse(bytes[i * numLeds * 3 + j * 3 + 0]), int.Parse(bytes[i * numLeds * 3 + j * 3 + 1]), int.Parse(bytes[i * numLeds * 3 + j * 3 + 2])); HSVColor c = HSVColor.FromRGB(rgb); animation[i][j] = c; } } return(new Animation(animation)); } catch (Exception e) { Debug.WriteLine("Error reading animation"); Debug.WriteLine(e.StackTrace); throw e; } }
void Init() { delaunayTriangulation = new DelaunayTriangulation(); Color.RGBToHSV(color, out hsvColor.h, out hsvColor.s, out hsvColor.v); orgPosList = new List <Vector3> (); // randomPoints for (var i = 0; i < num; i++) { orgPosList.Add(createVector(random(rect.xMin, rect.xMax), random(rect.yMin, rect.yMax))); } int pointCount = orgPosList.Count; // speed spList = new List <Vector3> (); for (int i = 0; i < pointCount; i++) { Vector3 sp = new Vector3(Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f)); spList.Add(sp); } // current currentPosList = new List <Vector3> (); currentPosList.AddRange(orgPosList); movePosList = new List <Vector3> (); for (int i = 0; i < pointCount; i++) { movePosList.Add(Vector3.zero); } // v color float h = hsvColor.h; hsvColors = new List <HSVColor> (); for (int i = 0; i < 7; i++) { HSVColor c = new HSVColor(h, 0, 0); hsvColors.Add(c); } for (int i = 0; i < pointCount; i++) { float s = Random.Range(0.5f, 1) * 0.5f; float b = Random.Range(0.3f, 1) * 0.5f; HSVColor c = new HSVColor(h, s, b); hsvColors.Add(c); } // mesh mesh = new Mesh(); mf.mesh = mesh; }
public static HSVColor FromColor(Color color) { HSVColor ret = new HSVColor(0f, 0f, 0f, color.a); float r = color.r; float g = color.g; float b = color.b; float max = Mathf.Max(r, Mathf.Max(g, b)); if (max <= 0) { return(ret); } float min = Mathf.Min(r, Mathf.Min(g, b)); float dif = max - min; if (max > min) { if (g == max) { ret.h = (b - r) / dif * 60f + 120f; } else if (b == max) { ret.h = (r - g) / dif * 60f + 240f; } else if (b > g) { ret.h = (g - b) / dif * 60f + 360f; } else { ret.h = (g - b) / dif * 60f; } if (ret.h < 0) { ret.h = ret.h + 360f; } } else { ret.h = 0; } ret.h *= 1f / 360f; ret.s = (dif / max) * 1f; ret.v = max; return(ret); }
public static HSVColor FromColor(Color color) { HSVColor ret = new HSVColor(0f, 0f, 0f, color.a); float r = color.r; float g = color.g; float b = color.b; float max = Mathf.Max(r, Mathf.Max(g, b)); if (max <= 0) { return ret; } float min = Mathf.Min(r, Mathf.Min(g, b)); float dif = max - min; if (max > min) { if (g == max) { ret.h = (b - r) / dif * 60f + 120f; } else if (b == max) { ret.h = (r - g) / dif * 60f + 240f; } else if (b > g) { ret.h = (g - b) / dif * 60f + 360f; } else { ret.h = (g - b) / dif * 60f; } if (ret.h < 0) { ret.h = ret.h + 360f; } } else { ret.h = 0; } ret.h *= 1f / 360f; ret.s = (dif / max) * 1f; ret.v = max; return ret; }
private static void GoldView(Led[] leds, LightingMode lightMode, GameState gameState) { HSVColor col = HSVColor.Black; if (gameState.ActivePlayer.CurrentGold >= GoldNotificationThreshold) { col = GoldColor; } foreach (int k in goldKeys) { leds[k].Color(col); } }
private void GoldView(LEDData data, GameState gameState) { HSVColor col = HSVColor.Black; if (gameState.ActivePlayer.CurrentGold >= GoldNotificationThreshold) { col = GoldColor; } foreach (int k in goldKeys) { data.Keyboard[k].Color(col); } }
public override void Update(GameTime gt) { base.Update(gt); foreach (var tile in GetTiles()) { //Convert color to HSV, increase hue, then put it back HSVColor hsv = ColorMath.RGBtoHSV(tile.Color); hsv.H += HUEINCREASE; tile.Color = ColorMath.HSVtoRGB(hsv); tile.Color.Action = ColorOutOfBoundsAction.WrapAround; } }
public void ToRGBAfterGetNew_Test(float h, float r, float g, float b) { // setup Color expected = new Color(r, g, b); HSVColor hsvColor = new HSVColor(Color.red); // perform hsvColor = hsvColor.GetNew(h); Color actual = hsvColor.ToRGB(); // assert Assert.AreEqual(expected, actual); }
public ColorPickerSlider( TrackType trackType, HSVColor hsvColor, ValueChanged <HSVColor> onColorChanged = null, bool displayThumbColor = false, bool fullThumbColor = false ) { this.trackType = trackType; this.hsvColor = hsvColor; this.onColorChanged = onColorChanged; this.displayThumbColor = displayThumbColor; this.fullThumbColor = fullThumbColor; }
public override void paint(Canvas canvas, Size size) { Rect rect = Offset.zero & size; var gradientV = new LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: new List <Color> { Colors.white, Colors.black } ); var gradientH = new LinearGradient( colors: new List <Color> { Colors.white, HSVColor.fromAHSV(1f, hsvColor.hue, 1f, 1f).toColor() } ); var paint = new Paint() { strokeWidth = 1.5f, style = PaintingStyle.stroke }; if (pointerColor != null) { paint.color = pointerColor; } else if (Utils.useWhiteForeground(hsvColor.toColor())) { paint.color = Colors.white; } else { paint.color = Colors.black; } canvas.drawRect(rect, new Paint() { shader = gradientV.createShader(rect) }); canvas.drawRect(rect, new Paint() { blendMode = BlendMode.multiply, shader = gradientH.createShader(rect) }); canvas.drawCircle( new Offset(size.width * hsvColor.saturation, size.height * (1 - hsvColor.value)), size.height * 0.04f, paint ); }
public Widget colorPickerArea() { return(new ClipRRect( borderRadius: widget.pickerAreaBorderRadius, child: new ColorPickerArea( currentHsvColor, (HSVColor color) => { setState(() => { currentHsvColor = color; }); widget.onColorChanged(currentHsvColor); }, widget.paletteType ) //ColorPickerArea )); //ClipRRect }
void UpdateRGBAControls(ColorValue value, object ignoreControl) { HSVColor hsvColor = HSVColor.FromRGB(value); if (ignoreControl != colorWheel) { colorWheel.HsvColor = hsvColor; } if (ignoreControl != colorGradientControl) { colorGradientControl.Value = (int)(hsvColor.Value * 255); colorGradientControl.TopColor = new HSVColor(hsvColor.Hue, hsvColor.Saturation, 1).ToColor(); colorGradientControl.BottomColor = Color.Black; } if (ignoreControl != numericUpDownRed) { numericUpDownRed.Value = (decimal)MathEx.Saturate(value.Red) * 255; } if (ignoreControl != numericUpDownGreen) { numericUpDownGreen.Value = (decimal)MathEx.Saturate(value.Green) * 255; } if (ignoreControl != numericUpDownBlue) { numericUpDownBlue.Value = (decimal)MathEx.Saturate(value.Blue) * 255; } if (ignoreControl != numericUpDownAlpha) { numericUpDownAlpha.Value = (decimal)(MathEx.Saturate(noAlpha ? 1 : value.Alpha) * 255); } if (ignoreControl != trackBarRed) { trackBarRed.Value = (int)(MathEx.Saturate(value.Red) * 1000); } if (ignoreControl != trackBarGreen) { trackBarGreen.Value = (int)(MathEx.Saturate(value.Green) * 1000); } if (ignoreControl != trackBarBlue) { trackBarBlue.Value = (int)(MathEx.Saturate(value.Blue) * 1000); } if (ignoreControl != trackBarAlpha) { trackBarAlpha.Value = (int)(MathEx.Saturate(noAlpha ? 1 : value.Alpha) * 1000); } }
public Widget colorPickerSlider(TrackType trackType) { return(new ColorPickerSlider( trackType, currentHsvColor, (HSVColor color) => { //UnityEngine.Debug.Log(color.toColor()); setState(() => { currentHsvColor = color; }); widget.onColorChanged(currentHsvColor.toColor()); }, displayThumbColor: widget.displayThumbColor, fullThumbColor: true )); }
public Color temperatureColor(float temperature) { HSVColor magenta = new HSVColor(0.90f, 1, 1); HSVColor red = new HSVColor(0, 1, 1); float t = MyMath.remap(temperature, min, max, 0, 1.166f); if (t >= 0.166f) { return(HSVColor.lerpHue(magenta, red, t - 0.166f).toRGB()); } else { return(Color.Lerp(Color.white, magenta.toRGB(), t / 0.166f)); } }
public static HSVColor FromRGB(Color rgb) { HSVColor hsv = new HSVColor(0.0f, 0.0f, 0.0f, rgb.a); float r = rgb.r; float g = rgb.g; float b = rgb.b; float max = Mathf.Max(r, g, b); if (max <= 0) return hsv; float min = Mathf.Min(r, g, b); float diff = max - min; if (max > min) { if (g == max) { hsv.h = (b - r) / diff * 60.0f + 60.0f * 2; } else if (b == max) { hsv.h = (r - g) / diff * 60.0f + 60.0f * 4; } else if (b > g) { hsv.h = (g - b) / diff * 60.0f + 60.0f * 6; } else { hsv.h = (g - b) / diff * 60.0f + 60.0f * 0; } if (hsv.h < 0) { hsv.h = hsv.h + 360.0f; } } hsv.h *= 1.0f / 360.0f; hsv.s = (diff / max) * 1.0f; hsv.v = max; return hsv; }
private Color GetNewBuildingColor() { HSVColor color = new HSVColor(hue, Random.Range(0.4f, 0.6f), Random.Range(0.7f, 0.9f)); return color.HSVToRGB(); }
public static Color HSVToRGB(HSVColor hsvColor) { int hi = Convert.ToInt32(Math.Floor(hsvColor.H / 60)) % 6; double f = hsvColor.H / 60 - Math.Floor(hsvColor.H / 60); hsvColor.V = hsvColor.V * 255; byte v = Convert.ToByte(hsvColor.V); byte p = Convert.ToByte(hsvColor.V * (1 - hsvColor.S)); byte q = Convert.ToByte(hsvColor.V * (1 - f * hsvColor.S)); byte t = Convert.ToByte(hsvColor.V * (1 - (1 - f) * hsvColor.S)); if (hi == 0) return Color.FromArgb(hsvColor.A, v, t, p); else if (hi == 1) return Color.FromArgb(hsvColor.A, q, v, p); else if (hi == 2) return Color.FromArgb(hsvColor.A, p, v, t); else if (hi == 3) return Color.FromArgb(hsvColor.A, p, q, v); else if (hi == 4) return Color.FromArgb(hsvColor.A, t, p, v); else return Color.FromArgb(hsvColor.A, v, p, q); }
// Generate random colour values into colour arrays and set color void generateNewColor(int index) { double range = 360d / ingredients.Length; double myHue = 0d; if (!initialPass) { myHue = ingredHues[index]; updateAvailableHues(index, (int)range, (int)myHue, true); } int hue; if(index < 5) { int[] a = new int[availableHuesLeft.Count]; availableHuesLeft.CopyTo(a); hue = a[r.Next(a.Length)]; } else { int[] a = new int[availableHuesRight.Count]; availableHuesRight.CopyTo(a); hue = a[r.Next(a.Length)]; } updateAvailableHues(index, (int)range, (int)hue, false); myHue = (double)hue + r.NextDouble() * Math.Pow(-1d, r.Next(2)); ingredHues[index] = myHue; Color32 color = new HSVColor(ingredHues[index], saturation, value).RgbColor; Renderer rend = ingredients[index].GetComponent<Renderer>(); rend.material.color = color; }
private void CieXYZChanged() { rgbColor = xyzColor; xyyColor = xyzColor; hsvColor = rgbColor; }
public void BurstTrailColor(Color color) { isBursting = true; currentColorHSV = WadeUtils.RGBToHSV(color); }
private void SetColorsHSV(int index, float h, float s, float v) { colors[0][index] = new HSVColor(h, 1f, 1f).ToColor(255); colors[1][index] = new Color32(255, 255, 255, (byte)((1 - s) * 255)); colors[2][index] = new Color32(0, 0, 0, (byte)((1 - v) * 255)); }
private void RgbChanged() { hsvColor = (HSVColor)rgbColor; xyzColor = rgbColor; xyyColor = xyzColor; //application.color = rgbColor; }
public static void Extract1Channel(HSV161616Image image, HSVColor plane, DoubleImage chan) { VisionLabPINVOKE.Extract1Channel__SWIG_78(HSV161616Image.getCPtr(image), (int)plane, DoubleImage.getCPtr(chan)); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); }
private void CiexyYChanged() { xyzColor = xyyColor; rgbColor = xyzColor; hsvColor = rgbColor; }
public static void Test() { HSVColor color; color = new HSVColor(Color.red); Debug.Log("red: " + color); color = new HSVColor(Color.green); Debug.Log("green: " + color); color = new HSVColor(Color.blue); Debug.Log("blue: " + color); color = new HSVColor(Color.grey); Debug.Log("grey: " + color); color = new HSVColor(Color.white); Debug.Log("white: " + color); color = new HSVColor(new Color(0.4f, 1f, 0.84f, 1f)); Debug.Log("0.4, 1f, 0.84: " + color); Debug.Log("164,82,84 .... 0.643137f, 0.321568f, 0.329411f :" + ToColor(new HSVColor(new Color(0.643137f, 0.321568f, 0.329411f)))); }
public static void BlendColors(Color color2) { HSVColor c1 = new HSVColor(color); HSVColor c2 = new HSVColor(color2); Debug.Log("4r=" + color.r + " g=" + color.g + " b=" + color.b); Debug.Log("h1=" + c1.hue + " h2=" + c2.hue); double delta1; double delta2; if (c1.hue > c2.hue) { delta1 = (360d - c1.hue) + c2.hue; } else { delta1 = (360d - c2.hue) + c1.hue; } delta2 = c2.hue - c1.hue; if (Math.Abs(delta1) >= Math.Abs(delta2)) { c1.hue += blendFactor * delta2; Debug.Log("diff=" + delta2); } else { Debug.Log("diff=" + delta1); if (c1.hue > c2.hue) { c1.hue += blendFactor * delta1; c1.hue %= 360; } else { c1.hue -= blendFactor * delta1; if (c1.hue < 0) { c1.hue = 360 + c1.hue; } } } Debug.Log("5new hue=" + c1.hue); h = c1.hue; color = c1.RgbColor; Debug.Log("r=" + color.r + " g=" + color.g + " b=" + color.b); }
public static Color ToColor(HSVColor hsvColor) { float r = hsvColor.v; float g = hsvColor.v; float b = hsvColor.v; if (hsvColor.s != 0) { float max = hsvColor.v; float dif = hsvColor.v * hsvColor.s; float min = hsvColor.v - dif; float h = hsvColor.h * 360f; if (h < 60f) { r = max; g = h * dif / 60f + min; b = min; } else if (h < 120f) { r = -(h - 120f) * dif / 60f + min; g = max; b = min; } else if (h < 180f) { r = min; g = max; b = (h - 120f) * dif / 60f + min; } else if (h < 240f) { r = min; g = -(h - 240f) * dif / 60f + min; b = max; } else if (h < 300f) { r = (h - 240f) * dif / 60f + min; g = min; b = max; } else if (h <= 360f) { r = max; g = min; b = -(h - 360f) * dif / 60 + min; } else { r = 0; g = 0; b = 0; } } return new Color(Mathf.Clamp01(r),Mathf.Clamp01(g),Mathf.Clamp01(b),hsvColor.a); }
public static string HSVColorToStr(HSVColor col) { string ret = VisionLabPINVOKE.HSVColorToStr((int)col); if (VisionLabPINVOKE.SWIGPendingException.Pending) throw VisionLabPINVOKE.SWIGPendingException.Retrieve(); return ret; }
public static HSVColor Lerp(HSVColor a, HSVColor b, float t) { float h,s; //check special case black (color.b==0): interpolate neither hue nor saturation! //check special case grey (color.s==0): don't interpolate hue! if(a.v==0){ h=b.h; s=b.s; }else if(b.v==0){ h=a.h; s=a.s; }else{ if(a.s==0){ h=b.h; }else if(b.s==0){ h=a.h; }else{ // works around bug with LerpAngle float angle = Mathf.LerpAngle(a.h * 360f, b.h * 360f, t); while (angle < 0f) angle += 360f; while (angle > 360f) angle -= 360f; h=angle/360f; } s=Mathf.Lerp(a.s,b.s,t); } return new HSVColor(h, s, Mathf.Lerp(a.v, b.v, t), Mathf.Lerp(a.a, b.a, t)); }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (this.State.ContainsKey("CurrentColor")) { SetCurrentColor((HSVColor)this.State["CurrentColor"]); } else if (NavigationContext.QueryString.ContainsKey("currentColor")) { Color color; if (TryGetColorFromText("#" + NavigationContext.QueryString["currentColor"], out color)) SetCurrentColor(ColorConverter.RGBToHSV(color)); } if (NavigationContext.QueryString.ContainsKey("defaultColor")) { Color color; if (TryGetColorFromText("#" + NavigationContext.QueryString["defaultColor"], out color)) defaultColor = ColorConverter.RGBToHSV(color); if (defaultColor == currentColor) { this.Focus(); // So focus doesn't go to TextBox and bring up keyboard this.ResetButton.IsEnabled = false; } } if (NavigationContext.QueryString.ContainsKey("settingName")) settingName = NavigationContext.QueryString["settingName"]; if (NavigationContext.QueryString.ContainsKey("showOpacity")) { bool newValue = Convert.ToBoolean(NavigationContext.QueryString["showOpacity"]); // Only do this if switching from showing to not showing, to guard against multiple navigations to this page // (for example, from locking/unlocking the phone) if (showOpacity && !newValue) { // Hide options for non-opaque colors AlphaPanel.Visibility = Visibility.Collapsed; TransparentPresetColor.Visibility = Visibility.Collapsed; // Spread out remaining UI Canvas.SetTop(ColorPresetsPanel, Canvas.GetTop(ColorPresetsPanel) + 14); Canvas.SetTop(SaturationValuePanel, Canvas.GetTop(SaturationValuePanel) + 30); Canvas.SetTop(HuePanel, Canvas.GetTop(HuePanel) + 50); } showOpacity = newValue; } }
private void TemperatureChanged() { xyzColor = (CIEXYZColour)temperature; xyyColor = (CIEXYYColor)xyzColor; rgbColor = (RGBColor)xyzColor; hsvColor = (HSVColor)rgbColor; //this.RgbChanged(); }