Example #1
0
        /// <summary>
        /// Creates a random color, but accepts a given random class instead of creating a new one.
        /// </summary>
        /// <param name="rnd">The random generator.</param>
        /// <returns>The created random color.</returns>
        protected Color CreateRandomColor(Random rnd)
        {
            var startColor = EditorSettings.StartColor;
            var endColor   = EditorSettings.EndColor;

            if (EditorSettings.HueSatLight)
            {
                double hLow = startColor.GetHue();
                var    dH   = endColor.GetHue() - hLow;
                double sLow = startColor.GetSaturation();
                var    ds   = endColor.GetSaturation() - sLow;
                double lLow = startColor.GetBrightness();
                var    dl   = endColor.GetBrightness() - lLow;
                var    aLow = startColor.A / 255.0;
                var    da   = (endColor.A - aLow) / 255.0;
                return(SymbologyGlobal.ColorFromHsl((rnd.NextDouble() * dH) + hLow, (rnd.NextDouble() * ds) + sLow, (rnd.NextDouble() * dl) + lLow).ToTransparent((float)((rnd.NextDouble() * da) + aLow)));
            }

            int rLow  = Math.Min(startColor.R, endColor.R);
            int rHigh = Math.Max(startColor.R, endColor.R);
            int gLow  = Math.Min(startColor.G, endColor.G);
            int gHigh = Math.Max(startColor.G, endColor.G);
            int bLow  = Math.Min(startColor.B, endColor.B);
            int bHigh = Math.Max(startColor.B, endColor.B);
            int iaLow = Math.Min(startColor.A, endColor.A);
            int aHigh = Math.Max(startColor.A, endColor.A);

            return(Color.FromArgb(rnd.Next(iaLow, aHigh), rnd.Next(rLow, rHigh), rnd.Next(gLow, gHigh), rnd.Next(bLow, bHigh)));
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EditorSettings"/> class.
 /// </summary>
 public EditorSettings()
 {
     _hsl                    = true;
     _useColor               = true;
     _startColor             = SymbologyGlobal.ColorFromHsl(5, .7, .7);
     _endColor               = SymbologyGlobal.ColorFromHsl(345, .8, .8);
     _maxSampleCount         = 10000;
     _intervalMethod         = IntervalMethod.EqualInterval;
     _rampColors             = true;
     _intervalSnapMethod     = IntervalSnapMethod.DataValue;
     _intervalRoundingDigits = 0;
     _numBreaks              = 5;
 }
Example #3
0
        /// <summary>
        /// Creates a color with the same hue and saturation but that is slightly darker than this color.
        /// </summary>
        /// <param name="self">The starting color.</param>
        /// <param name="brightness">The floating point value of brightness to add to this color.</param>
        /// if the combined result is less than 0, the result will equal 0.
        /// <returns>A color darker than this color.</returns>
        public static Color Darker(this Color self, float brightness)
        {
            float b = self.GetBrightness() - brightness;

            if (b < 0F)
            {
                b = 0F;
            }
            if (b > 1F)
            {
                b = 1F;
            }
            return(Color.FromArgb(self.A, SymbologyGlobal.ColorFromHsl(self.GetHue(), self.GetSaturation(), b)));
        }
Example #4
0
        private static List <Color> CreateRampColors(int numColors, float minSat, float minLight, int minHue, float maxSat, float maxLight, int maxHue, int hueShift, int minAlpha, int maxAlpha)
        {
            List <Color> result = new List <Color>(numColors);
            double       ds     = (maxSat - (double)minSat) / numColors;
            double       dh     = (maxHue - (double)minHue) / numColors;
            double       dl     = (maxLight - (double)minLight) / numColors;
            double       dA     = (maxAlpha - (double)minAlpha) / numColors;

            for (int i = 0; i < numColors; i++)
            {
                double h = (minHue + dh * i) + hueShift % 360;
                double s = minSat + ds * i;
                double l = minLight + dl * i;
                float  a = (float)(minAlpha + dA * i) / 255f;
                result.Add(SymbologyGlobal.ColorFromHsl(h, s, l).ToTransparent(a));
            }
            return(result);
        }
Example #5
0
        private static List <Color> CreateRampColors(int numColors, float minSat, float minLight, int minHue, float maxSat, float maxLight, int maxHue, int hueShift, int minAlpha, int maxAlpha)
        {
            var result = new List <Color>(numColors);
            var ds     = (maxSat - (double)minSat) / numColors;
            var dh     = (maxHue - (double)minHue) / numColors;
            var dl     = (maxLight - (double)minLight) / numColors;
            var dA     = (maxAlpha - (double)minAlpha) / numColors;

            for (var i = 0; i < numColors; i++)
            {
                var h = (minHue + (dh * i)) + (hueShift % 360);
                var s = minSat + (ds * i);
                var l = minLight + (dl * i);
                var a = (float)(minAlpha + (dA * i)) / 255f;
                result.Add(SymbologyGlobal.ColorFromHsl(h, s, l).ToTransparent(a));
            }

            return(result);
        }