private bool OnSubmit(out string error, string input)
        {
            Regex hexRegex = new Regex(InternalResources.Constants.REGEX_HEXADECIMAL_COLOR);
            Match hexMatch = hexRegex.Match(input);

            if (hexMatch.Success)
            {
                Menu.modifiedColorsOrCar_ = true;
                Color    color    = hexMatch.Groups["color"].Captures[0].Value.ToColor();
                ColorHSB colorHSB = color.ToColorHSB();

                Menu.colorPicker_.Color_           = color;
                Menu.colorPicker_.Position_        = new Vector2(colorHSB.s, colorHSB.b);
                Menu.colorPicker_.hueSlider_.value = colorHSB.h;
                Menu.colorPicker_.NewValuesSet(true, true);

                error = "";
                return(true);
            }
            else
            {
                error = "Invalid hex code";
                return(false);
            }
        }
Ejemplo n.º 2
0
    public static Color ToColor(ColorHSB hsbColor)
    {
        float r = hsbColor.b;
        float g = hsbColor.b;
        float b = hsbColor.b;

        if (hsbColor.s != 0)
        {
            float max = hsbColor.b;
            float dif = hsbColor.b * hsbColor.s;
            float min = hsbColor.b - dif;

            float h = hsbColor.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), hsbColor.a));
    }
        private static Color DotColor(int value, int length)
        {
            float angle = 360f * value / length;

            ColorHSB color = new ColorHSB(angle, 0.75f, 0.75f);

            return(color.ToColor());
        }
Ejemplo n.º 4
0
    public ColorHSB(Color col)
    {
        ColorHSB colHSB = FromColor(col);

        h = colHSB.h;
        s = colHSB.s;
        b = colHSB.b;
        a = colHSB.a;
    }
Ejemplo n.º 5
0
    public ColorHSB(Color col)
    {
        ColorHSB temp = FromColor(col);

        h = temp.h;
        s = temp.s;
        b = temp.b;
        a = temp.a;
    }
        private TestColor TestColorHSB()
        {
            var color = ColorHSB.FromColor(testColor);

            var color2      = (ColorRGB)color.ToRgb();;
            var nativeValue = string.Format("H:{0:0.0#} S:{1:0.0#} B:{2:0.0#}", color.H, color.S, color.B);

            return(new TestColor {
                Name = "HSB", Value = color2.ToHex(), NativeValue = nativeValue
            });
        }
Ejemplo n.º 7
0
    public static ColorHSB FromColor(Color color)
    {
        ColorHSB ret = new ColorHSB(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.b  = max;

        return(ret);
    }
Ejemplo n.º 8
0
        public void RGBtoHSBConversion()
        {
            var rgb          = ColorRGB.FromHex("#6653B2");
            var hsb          = (ColorHSB)ColorHSB.FromColor(rgb);
            var rgbConverted = (ColorRGB)hsb.ToRgb();

            // HSL
            Assert.AreEqual(hsb.Hue, 252);
            Assert.AreEqual(hsb.Saturation, 53.37);
            Assert.AreEqual(hsb.Brightness, 69.8);

            // RGB Converted
            Assert.AreEqual(rgbConverted.Red, 102);
            Assert.AreEqual(rgbConverted.Green, 83);
            Assert.AreEqual(rgbConverted.Blue, 178);
        }
Ejemplo n.º 9
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            isLoaded = false;
            ColorHSB temp = new ColorHSB(MainPage.GlobalColor);

            HueSlider.Value  = temp.Hue;
            SatSlider.Value  = temp.Saturation;
            BrgSlider.Value  = temp.Brightness;
            HueValueBox.Text = ((int)HueSlider.Value).ToString() + "º";
            SatValueBox.Text = ((int)SatSlider.Value).ToString();
            BrgValueBox.Text = ((int)BrgSlider.Value).ToString();

            HSBColor = temp;
            isLoaded = true;

            RefreshWheel();
        }
Ejemplo n.º 10
0
        // Steps 5, 6, 8, 9, 10, 12, 15, 18, 20, 24, 30, 36, 40, 45, 60, 72, 90, 120, 180
        public static IColorSpace [] GenerateColors(int steps, double hue, double saturation, double brightness)
        {
            int distance   = 360 / steps;
            var colors     = new IColorSpace [steps];
            var startColor = new ColorHSB(hue, saturation, brightness);

            colors [0] = startColor;
            for (int i = 1; i < steps; i++)
            {
                colors [i] = new ColorHSB(
                    startColor.H + i * distance,
                    startColor.S,
                    startColor.B
                    );
            }

            return(colors);
        }
Ejemplo n.º 11
0
    public static ColorHSB Lerp(ColorHSB a, ColorHSB 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.b == 0)
        {
            h = b.h;
            s = b.s;
        }
        else if (b.b == 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 ColorHSB(h, s, Mathf.Lerp(a.b, b.b, t), Mathf.Lerp(a.a, b.a, t)));
    }
Ejemplo n.º 12
0
 public void RefreshColors()
 {
     if (!hasInitializedContent)
     {
         return;
     }                                  // Haven't initted content? Do nothin'.
     // Grounds
     if (editorSettings.DoShowClusters) // Color ALL by my CLUSTER!
     {
         float s = myRD.isClustStart ? 0.6f : 0.34f;
         Color groundColor;
         if (!myRD.IsInCluster)
         {
             groundColor = new ColorHSB(0.2f, 0.05f, 0.4f).ToColor();
         }                                                                               // No Cluster? Gray-ish.
         else
         {
             groundColor = new ColorHSB(((20 + myRD.MyCluster.ClustIndex * 40) / 360f) % 1, s, 0.5f).ToColor();
         }
         if (myRD.IsSecret)
         {
             groundColor = Color.Lerp(groundColor, Color.black, 0.3f);
         }                                                                            // Secret? Darker grounds!
         for (int i = 0; i < srs_grounds.Count; i++)
         {
             srs_grounds[i].color = groundColor;
         }
     }
     else // Otherwise, color EACH how Ground ACTUALLY looks.
          //Color groundColor = new Color(91/255f,107/255f,67/255f, 0.92f);
     {
         for (int i = 0; i < srs_grounds.Count; i++)
         {
             srs_grounds[i].color = Ground.GetBodyColor(groundDatas[i], myRD.WorldIndex);
         }
     }
     // Openings
     for (int i = 0; i < srs_openings.Count; i++)
     {
         srs_openings[i].color = GetOpeningColor(myRD.Openings[i]);
     }
 }
Ejemplo n.º 13
0
        private ColorHSB[] SingleColorPalette(int hue)
        {
            ColorHSB[] palette = new ColorHSB[11];
            for (int step = 0; step < 11; step++)
            {
                if (step < 6)
                {
                    palette[step] = new ColorHSB(hue, 100, step * 20);
                }
                if (step == 6)
                {
                    palette[step] = new ColorHSB(hue, 100, 100);
                }
                if (step > 6)
                {
                    palette[step] = new ColorHSB(hue, 100 - ((step - 5) * 20), 100);
                }
            }

            return(palette);
        }
Ejemplo n.º 14
0
    static public Color GetBodyColor(int worldIndex, bool isBouncy, bool mayBounce, bool doRechargePlayer)
    {
        Color color = Colors.GroundBaseColor(worldIndex);

        if (isBouncy)   // Bouncy? Brighten it much!
        {
            ColorHSB colorHSB = new ColorHSB(color);
            colorHSB.s = Mathf.Min(1, 0.3f + colorHSB.s * 1.4f);
            colorHSB.b = Mathf.Min(1f, 0.3f + colorHSB.b * 1.4f);
            color      = colorHSB.ToColor();
        }
        if (!mayBounce)
        {
            color = Color.Lerp(color, Color.black, 0.7f);
        }
        if (!doRechargePlayer)
        {
            color = Color.Lerp(color, Color.black, 0.4f);
        }
        return(color);
    }
Ejemplo n.º 15
0
        // ----------------------------------------------------------------
        //  Doers
        // ----------------------------------------------------------------
        private void RefreshVisuals()
        {
            // Values.
            int totalSnacksEaten = GameManagers.Instance.DataManager.SnackCountGame.Eaten_All;

            canUnlockMe = !myClustData.IsUnlocked && totalSnacksEaten >= myClustData.NumSnacksReq;

            // Texts and back!
            int numAdditionalSnacksReq = Mathf.Max(0, myClustData.NumSnacksReq - totalSnacksEaten);
            int numSnacksInClust       = myClustData.SnackCount.Total_All;

            //myButton.interactable = myClustData.IsUnlocked;
            go_snacksReq.SetActive(!myClustData.IsUnlocked);
            //go_snacksLeft.SetActive(myClustData.IsUnlocked && numSnacksInClust>0);
            t_snacksReq.text = numAdditionalSnacksReq.ToString();
            //t_snacksLeft.text = myClustData.SnackCount.Eaten_All + " / " + numSnacksInClust; //numSnacksLeft.ToString();
            Color backColor = new ColorHSB(worldHue, 0.5f, 0.5f).ToColor();

            if (!myClustData.IsUnlocked && !canUnlockMe)   // locked? Make darker.
            {
                backColor = Color.Lerp(backColor, Color.black, 0.5f);
            }
            i_back.color = backColor;

            // RoomViews!
            Color roomColorVisited = new ColorHSB(worldHue, 0.5f, 0.95f, 0.1f).ToColor();

            foreach (RoomView roomView in roomViews)
            {
                roomView.UpdateColor(roomColorVisited);
            }

            // Completion-ness!
            bool didCompleteClust = myClustData.IsUnlocked && !myClustData.SnackCount.AreUneatenSnacks(PlayerTypes.Any);// && myClustData.HasPlayerBeenInEveryRoom();

            i_checkmark.color = didCompleteClust ? new Color(0.3f, 1f, 0f) : new Color(0, 0, 0, 0.1f);
        }
Ejemplo n.º 16
0
    async private void Generate(object sender = null, EventArgs e = null)
    {
        if (isScrolling && sender != ScrollButton)
        {
            return;
        }

        do
        {
            // Create noise generators
            var genNoise  = new FastNoiseLite();
            var warpNoise = new FastNoiseLite();

            int w = (int)PreviewWidth.Value;
            int h = (int)PreviewHeight.Value;

            if (w <= 0 || h <= 0)
            {
                return;
            }

            genNoise.SetNoiseType((FastNoiseLite.NoiseType)NoiseType.SelectedIndex);
            genNoise.SetRotationType3D((FastNoiseLite.RotationType3D)RotationType3D.SelectedIndex);
            genNoise.SetSeed((int)Seed.Value);
            genNoise.SetFrequency((float)Frequency.Value);
            genNoise.SetFractalType((FastNoiseLite.FractalType)FractalType.SelectedIndex);
            genNoise.SetFractalOctaves((int)FractalOctaves.Value);
            genNoise.SetFractalLacunarity((float)FractalLacunarity.Value);
            genNoise.SetFractalGain((float)FractalGain.Value);
            genNoise.SetFractalWeightedStrength((float)FractalWeightedStrength.Value);
            genNoise.SetFractalPingPongStrength((float)FractalPingPongStrength.Value);

            genNoise.SetCellularDistanceFunction((FastNoiseLite.CellularDistanceFunction)CellularDistanceFunction.SelectedIndex);
            genNoise.SetCellularReturnType((FastNoiseLite.CellularReturnType)CellularReturnType.SelectedIndex);
            genNoise.SetCellularJitter((float)CellularJitter.Value);

            warpNoise.SetSeed((int)Seed.Value);
            warpNoise.SetDomainWarpType((FastNoiseLite.DomainWarpType)DomainWarp.SelectedIndex - 1);
            warpNoise.SetRotationType3D((FastNoiseLite.RotationType3D)DomainWarpRotationType3D.SelectedIndex);
            warpNoise.SetDomainWarpAmp((float)DomainWarpAmplitude.Value);
            warpNoise.SetFrequency((float)DomainWarpFrequency.Value);
            warpNoise.SetFractalType((FastNoiseLite.FractalType)Enum.Parse(typeof(FastNoiseLite.FractalType), DomainWarpFractal.SelectedKey));
            warpNoise.SetFractalOctaves((int)DomainWarpFractalOctaves.Value);
            warpNoise.SetFractalLacunarity((float)DomainWarpFractalLacunarity.Value);
            warpNoise.SetFractalGain((float)DomainWarpFractalGain.Value);

            if (ImageData.Length != w * h)
            {
                ImageData = new int[w * h];
            }

            float noise;
            float minN = float.MaxValue;
            float maxN = float.MinValue;
            float avg  = 0;

            bool get3d  = Is3D.Checked == true; // Stupid!
            bool invert = Invert.Checked == true;

            // Timer
            Stopwatch sw = new Stopwatch();

            int index = 0;
            if (VisualiseDomainWarp.Checked != true)
            {
                var  noiseValues = new float[w * h];
                bool warp        = DomainWarp.SelectedIndex > 0;

                sw.Start();
                for (var y = h / -2; y < h / 2; y++)
                {
                    for (var x = w / -2; x < w / 2; x++)
                    {
                        FNfloat xf = x;
                        FNfloat yf = y;
                        FNfloat zf = zPos;


                        if (get3d)
                        {
                            if (warp)
                            {
                                warpNoise.DomainWarp(ref xf, ref yf, ref zf);
                            }

                            noise = genNoise.GetNoise(xf, yf, zf);
                        }
                        else
                        {
                            if (warp)
                            {
                                warpNoise.DomainWarp(ref xf, ref yf);
                            }

                            noise = genNoise.GetNoise(xf, yf);
                        }

                        avg += noise;
                        maxN = Math.Max(maxN, noise);
                        minN = Math.Min(minN, noise);
                        noiseValues[index++] = noise;
                    }
                }
                sw.Stop();

                avg /= index - 1;
                float scale = 255 / (maxN - minN);

                for (var i = 0; i < noiseValues.Length; i++)
                {
                    int value = (int)MathF.Round(Math.Clamp((noiseValues[i] - minN) * scale, 0, 255));

                    if (invert)
                    {
                        value = 255 - value;
                    }

                    ImageData[i]  = value;
                    ImageData[i] |= value << 8;
                    ImageData[i] |= value << 16;
                }
            }
            else
            {
                var noiseValues = new float[w * h * 3];

                sw.Start();
                for (var y = -h / 2; y < h / 2; y++)
                {
                    for (var x = -w / 2; x < w / 2; x++)
                    {
                        FNfloat xf = x;
                        FNfloat yf = y;
                        FNfloat zf = zPos;

                        if (get3d)
                        {
                            warpNoise.DomainWarp(ref xf, ref yf, ref zf);
                        }
                        else
                        {
                            warpNoise.DomainWarp(ref xf, ref yf);
                        }

                        xf -= x;
                        yf -= y;
                        zf -= zPos;

                        avg += (float)(xf + yf);
                        maxN = Math.Max(maxN, (float)Math.Max(xf, yf));
                        minN = Math.Min(minN, (float)Math.Min(xf, yf));

                        noiseValues[index++] = (float)xf;
                        noiseValues[index++] = (float)yf;

                        if (get3d)
                        {
                            avg += (float)zf;
                            maxN = Math.Max(maxN, (float)zf);
                            minN = Math.Min(minN, (float)zf);
                            noiseValues[index++] = (float)zf;
                        }
                    }
                }
                sw.Stop();

                if (get3d)
                {
                    avg /= (index - 1) * 3;
                }
                else
                {
                    avg /= (index - 1) * 2;
                }

                index = 0;
                float scale = 1 / (maxN - minN);

                for (var i = 0; i < ImageData.Length; i++)
                {
                    Color color = new Color();

                    if (get3d)
                    {
                        color.R = (noiseValues[index++] - minN) * scale;
                        color.G = (noiseValues[index++] - minN) * scale;
                        color.B = (noiseValues[index++] - minN) * scale;
                    }
                    else
                    {
                        var vx = (noiseValues[index++] - minN) / (maxN - minN) - 0.5f;
                        var vy = (noiseValues[index++] - minN) / (maxN - minN) - 0.5f;

                        ColorHSB hsb = new ColorHSB();

                        hsb.H = MathF.Atan2(vy, vx) * (180 / MathF.PI) + 180;
                        hsb.B = Math.Min(1.0f, MathF.Sqrt(vx * vx + vy * vy) * 2);
                        hsb.S = 0.9f;

                        color = hsb.ToColor();
                    }

                    if (Invert.Checked == true)
                    {
                        color.Invert();
                    }

                    ImageData[i] = color.ToArgb();
                }
            }

            // Set image
            Bitmap      = new Bitmap(w, h, PixelFormat.Format32bppRgb, ImageData);
            Image.Image = Bitmap;

            // Set info labels
            Time.Text = "Time (ms): " + sw.ElapsedMilliseconds.ToString();
            Mean.Text = "Mean: " + avg.ToString();
            Min.Text  = "Min: " + minN.ToString();
            Max.Text  = "Max: " + maxN.ToString();

            // Sets the client (inner) size of the window for your content
            ClientSize = new Size(Math.Max((int)PreviewWidth.Value, 768), Math.Max((int)PreviewHeight.Value, 768)) + windowSizeOffset;

            if (isScrolling)
            {
                await Task.Delay(50);

                try
                {
                    zPos += ((float)Frequency.Value) * 100.0f;
                }
                catch (Exception ex) { MessageBox.Show("Frequency error: " + ex.ToString()); }
            }
        }while (isScrolling);
    }
Ejemplo n.º 17
0
        private void Update(HarmoniesType htt)
        {
            OutputPanel.Children.Clear();
            ColorHSB          color     = new ColorHSB(MainPage.GlobalColor);
            List <ColorHSB[]> harmonies = new List <ColorHSB[]>();
            List <int>        hues      = new List <int>();
            int colorCount;

            switch (htt)
            {
            case HarmoniesType.Analogous:
                colorCount = 3;
                hues.Add(color.Hue);
                hues.Add(color.Hue - 30 >= 0 ? color.Hue - 30 : color.Hue + 330);
                hues.Add(color.Hue + 30 <= 360?color.Hue + 30:color.Hue - 330);
                break;

            case HarmoniesType.Triadric:
                colorCount = 4;
                hues.Add(color.Hue);
                hues.Add(color.Hue + 90 <= 360 ? color.Hue + 90 : color.Hue - 270);
                hues.Add(color.Hue + 180 <= 360 ? color.Hue + 180 : color.Hue - 180);
                hues.Add(color.Hue + 270 <= 360 ? color.Hue + 270 : color.Hue - 90);
                break;

            case HarmoniesType.Complimentary:
                colorCount = 2;
                hues.Add(color.Hue);
                hues.Add(color.Hue + 180 <= 360 ? color.Hue + 180 : color.Hue - 180);
                break;

            case HarmoniesType.SplitComplimentary:
                colorCount = 3;
                hues.Add(color.Hue);
                hues.Add(color.Hue + 150 <= 360 ? color.Hue + 150 : color.Hue - 230);
                hues.Add(color.Hue - 150 >= 0 ? color.Hue - 150 : color.Hue + 230);
                break;

            case HarmoniesType.DoubleComplimentary:
                colorCount = 4;
                hues.Add(color.Hue - 30 >= 0 ? color.Hue - 30 : color.Hue + 330);
                hues.Add(color.Hue + 30 <= 360 ? color.Hue + 30 : color.Hue - 330);
                hues.Add(color.Hue + 150 <= 360 ? color.Hue + 150 : color.Hue - 230);
                hues.Add(color.Hue - 150 >= 0 ? color.Hue - 150 : color.Hue + 230);
                break;

            default:
                colorCount = 1;
                hues.Add(color.Hue);
                break;
            }

            foreach (int i in hues)
            {
                harmonies.Add(SingleColorPalette(i));
            }

            for (int i = 0; i < colorCount; i++)
            {
                StackPanel sPanel = new StackPanel
                {
                    Orientation = Orientation.Vertical
                };
                for (int e = 0; e < 11; e++)
                {
                    Rectangle rect = new Rectangle
                    {
                        Height = 25,
                        Width  = 50,
                        Fill   = new SolidColorBrush(harmonies[i][e].ColorRGB)
                    };
                    sPanel.Children.Add(rect);
                }
                OutputPanel.Children.Add(sPanel);
            }
        }