Пример #1
0
        ///////////////////////////////////////////////////////////////////////////////
        // Public methods                                                            //
        ///////////////////////////////////////////////////////////////////////////////
        #region Public Methods and Operators

        /// <summary>
        /// Returns a colored pallet for the given hue and saturation.
        /// </summary>
        /// <param name="hue">
        /// A <see cref="float"/> with the hue to use.
        /// </param>
        /// <param name="hueConstraint">
        /// A <see cref="float"/> with the hue constraint to use.
        /// </param>
        /// <param name="saturation">
        /// A <see cref="float"/> with the saturation to use.
        /// </param>
        /// <param name="x">
        /// A <see cref="float"/> with ???
        /// </param>
        /// <returns>
        /// An array of colors defining the pallet.
        /// </returns>
        public Color[] GetColoredPallet(float hue, float hueConstraint, float saturation, float x)
        {
            if (this.colorType != ColorType.HSL && this.colorType != ColorType.HSV)
            {
                throw new NotImplementedException(string.Format("Not implemented color type: \"{0}\"", this.colorType));
            }

            // Hue
            float hueDiff = this.palletInfo.HueAvg - hue;

            // Saturation
            float satDiff;
            float satConstraint;
            float satAux;

            this.CalculateParameters(
                saturation, this.palletInfo.SatMin, this.palletInfo.SatMax, out satDiff, out satConstraint, out satAux);

            // X
            float diffX;
            float constraintX;
            float auxX;

            this.CalculateParameters(x, this.palletInfo.XMin, this.palletInfo.XMax, out diffX, out constraintX, out auxX);

            var      result = new Color[this.sourcePallet.Length];
            HSXColor sourceColor;
            HSXColor resultColor;

            // Not Tested yet
            for (int i = 0; i < this.sourcePallet.Length; i++)
            {
                sourceColor = this.sourcePallet[i];
                resultColor =
                    new HSXColor(
                        sourceColor.Hue + ((this.palletInfo.HueAvg - sourceColor.Hue) * hueConstraint) - hueDiff,
                        sourceColor.Saturation + ((satAux - sourceColor.Saturation) * satConstraint) + satDiff,
                        sourceColor.ValueLuminanceBrightness + ((auxX - sourceColor.ValueLuminanceBrightness) * constraintX) + diffX);

                result[i] = this.IsHSL ? ConvertColor.HSLToRGB(resultColor) : ConvertColor.HSVToRGB(resultColor);
            }

            return(result);
        }
Пример #2
0
 /// <summary>
 /// HSL to RGB Color Converter
 /// </summary>
 /// <param name="hslColor">
 /// HSL Color to be converted.
 /// </param>
 /// <returns>
 /// The HSL color as a RGB <see cref="Color"/>
 /// </returns>
 public static Color HSLToRGB(HSXColor hslColor)
 {
     return(HSLToRGB(hslColor.Hue, hslColor.Saturation, hslColor.ValueLuminanceBrightness));
 }