Ejemplo n.º 1
0
        /// <summary>
        /// retrieve rainbow rgb color from a double value between [0,1]
        /// </summary>
        public static IRgb FromRainbow(this double factor)
        {
            /*
             * test : http://serennu.com/colour/hsltorgb.php
             * RGB: 218 165 32
             * HSL: 43° 74% 49%
             * Hex: #DAA520
             */

            /*
             * RAINBOW COLORS
             *
             * red hsl(0,100%,50%)
             * orange hsl(30,100%,50%)
             * yellow hsl(60,100%,50%)
             * green hsl(120,100%,50%)
             * cyan hsl(180,100%,50%)
             * blue hsl(240,100%,50%)
             * purple hsl(270,100%,50%)
             * magenta hsl(300,100%,50%)
             */
            var hsl = new Hsl();

            // rainbow hue on range [0,240]
            hsl.H = (1.0 - factor) * 240;

            // 100% saturation
            hsl.S = 100;

            // 50% luminance
            hsl.L = 50;

            return(hsl.ToRgb());
        }
Ejemplo n.º 2
0
        internal static Color ToColor(this Hsl hsl)
        {
            Func <double, int> round = x => (int)Math.Round(x);
            var rgb = hsl.ToRgb();

            return(Color.FromArgb(round(rgb.R), round(rgb.G), round(rgb.B)));
        }