コード例 #1
0
    /// <summary>
    /// Returns a list of colors that are monochromatic in relation to the source
    /// </summary>
    public static List <Color> Monochromatic(Color sourceColor, int howMany = 4)
    {
        List <Color> palette = new List <Color>();

        HSL source = HSL.fromColor(sourceColor);                //Convert to HSL

        for (int i = 0; i < howMany; i++)
        {
            HSL hsl = HSL.Copy(source);         //Create a copy of the source HSL
            hsl.Lightness *= (howMany / 2 - i); //Change the lightness of it
            Color color = hsl.toColor();        //Convert it back
            color.a = sourceColor.a;            //Add back in the Alpha value
            palette.Add(color);                 //Add it to the palette
        }

        return(palette);
    }
コード例 #2
0
    /// <summary>
    /// Returns a list of colors that analagously related to the source .
    /// </summary>
    public static List <Color> Analagous(Color sourceColor, int howMany = 2)
    {
        List <Color> palette = new List <Color>();

        HSL   source    = HSL.fromColor(sourceColor);           //Convert to HSL
        float increment = 0.083f;
        float top       = source.Hue + (increment * (howMany / 2));

        for (int i = 0; i < howMany; i++)
        {
            HSL hsl = HSL.Copy(source);         //Create a copy of the source HSL
            hsl.Hue -= top - (i * increment);   //Change the lightness of it
            Color color = hsl.toColor();        //Convert it back
            color.a = sourceColor.a;            //Add back in the Alpha value
            palette.Add(color);                 //Add it to the palette
        }

        return(palette);


        /*
         *      List<Color> palette = new List<Color>();
         *
         *      HSL hsl1 = HSL.fromColor(sourceColor);		//Convert to HSL
         *      HSL hsl2 = HSL.Copy(hsl1);
         *
         *      hsl1.Hue += 0.083f;
         *      hsl2.Hue -= 0.083f;
         *
         *      //Do nothing to saturation and lightness
         *
         *      Color color1 = hsl1.toColor();  //Convert this back to RGB
         *      Color color2 = hsl2.toColor();  //Convert this back to RGB
         *
         *      color1.a = sourceColor.a;			//Add back in the A value
         *      palette.Add(color1);
         *      color2.a = sourceColor.a;			//Add back in the A value
         *      palette.Add(color2);
         *
         *      return palette;
         */
    }
コード例 #3
0
    /// <summary>
    /// Returns a list of colors that are triadic in relation to the source
    /// </summary>
    public static List <Color> Triadic(Color sourceColor)
    {
        List <Color> palette = new List <Color>();

        HSL hsl1 = HSL.fromColor(sourceColor);          //Convert to HSL
        HSL hsl2 = HSL.Copy(hsl1);

        hsl1.Hue += 0.33f;
        hsl2.Hue -= 0.33f;

        //Do nothing to saturation and lightness

        Color color1 = hsl1.toColor();  //Convert this back to RGB
        Color color2 = hsl2.toColor();  //Convert this back to RGB

        color1.a = sourceColor.a;       //Add back in the A value
        palette.Add(color1);
        color2.a = sourceColor.a;       //Add back in the A value
        palette.Add(color2);

        return(palette);
    }