@@ -66,70 +66,61 @@ class KvColorPalette {
6666 * this method generate a list of colors with different alpha values.
6767 *
6868 * @param givenColor The color to generate the alpha values for.
69+ * @param colorCount The number of colors to generate. In default that returns 10 colors.
70+ * This accept integer value in a range of 2 - 30. Even someone passes number more than 30, this will returns only 30 colors.
6971 * @return A list of colors.
7072 */
71- fun generateAlphaColorPalette (givenColor : Color ): List <Color > =
72- listOf (
73- Color (givenColor.red, givenColor.green, givenColor.blue, 1f ),
74- Color (givenColor.red, givenColor.green, givenColor.blue, .9f ),
75- Color (givenColor.red, givenColor.green, givenColor.blue, .8f ),
76- Color (givenColor.red, givenColor.green, givenColor.blue, .7f ),
77- Color (givenColor.red, givenColor.green, givenColor.blue, .6f ),
78- Color (givenColor.red, givenColor.green, givenColor.blue, .5f ),
79- Color (givenColor.red, givenColor.green, givenColor.blue, .4f ),
80- Color (givenColor.red, givenColor.green, givenColor.blue, .3f ),
81- Color (givenColor.red, givenColor.green, givenColor.blue, .2f ),
82- Color (givenColor.red, givenColor.green, givenColor.blue, .1f ),
83- )
73+ fun generateAlphaColorPalette (givenColor : Color , colorCount : Int = 10): List <Color > {
74+ val colorList = mutableListOf<Color >()
75+ val reviseColorCount = ColorUtil .validateAndReviseColorCount(colorCount)
76+ for (i in reviseColorCount downTo 1 ) {
77+ colorList.add(Color (givenColor.red, givenColor.green, givenColor.blue, ((1f / colorCount)* i)))
78+ }
79+ return colorList
80+ }
8481
8582 /* *
8683 * Generate a list of colors with color saturation values. According to the feeding color,
8784 * this method generate a list of color with different saturation values.
8885 *
8986 * @param givenColor The color to generate the saturation values for.
87+ * @param colorCount The number of colors to generate. In default that returns 10 colors.
88+ * This accept integer value in a range of 2 - 30. Even someone passes number more than 30, this will returns only 30 colors.
9089 * @return A list of colors.
9190 */
92- fun generateSaturationColorPalette (givenColor : Color ): List <Color > {
91+ fun generateSaturationColorPalette (givenColor : Color , colorCount : Int = 10 ): List <Color > {
9392 val hue = givenColor.hsl.hue
9493 val lightness = givenColor.hsl.lightness
9594
96- return listOf (
97- Color .hsl(hue = hue, saturation = 1f , lightness = lightness),
98- Color .hsl(hue = hue, saturation = 0.9f , lightness = lightness),
99- Color .hsl(hue = hue, saturation = 0.8f , lightness = lightness),
100- Color .hsl(hue = hue, saturation = 0.7f , lightness = lightness),
101- Color .hsl(hue = hue, saturation = 0.6f , lightness = lightness),
102- Color .hsl(hue = hue, saturation = 0.5f , lightness = lightness),
103- Color .hsl(hue = hue, saturation = 0.4f , lightness = lightness),
104- Color .hsl(hue = hue, saturation = 0.3f , lightness = lightness),
105- Color .hsl(hue = hue, saturation = 0.2f , lightness = lightness),
106- Color .hsl(hue = hue, saturation = 0.1f , lightness = lightness)
107- )
95+ val colorList = mutableListOf<Color >()
96+ val reviseColorCount = ColorUtil .validateAndReviseColorCount(colorCount)
97+
98+ for (i in reviseColorCount downTo 1 ) {
99+ colorList.add(Color .hsl(hue = hue, saturation = ((1f / colorCount)* i), lightness = lightness))
100+ }
101+ return colorList
108102 }
109103
110104 /* *
111105 * Generate a list of colors with color lightness values. According to the feeding color,
112106 * this method generate a list of color with different lightness values.
113107 *
114108 * @param givenColor The color to generate the lightness values for.
109+ * @param colorCount The number of colors to generate. In default that returns 10 colors.
110+ * This accept integer value in a range of 2 - 30. Even someone passes number more than 30, this will returns only 30 colors.
115111 * @return A list of colors.
116112 */
117- fun generateLightnessColorPalette (givenColor : Color ): List <Color > {
113+ fun generateLightnessColorPalette (givenColor : Color , colorCount : Int = 10 ): List <Color > {
118114 val hue = givenColor.hsl.hue
119115 val saturation = givenColor.hsl.saturation
120116
121- return listOf (
122- Color .hsl(hue = hue, saturation = saturation, lightness = 1f ),
123- Color .hsl(hue = hue, saturation = saturation, lightness = 0.9f ),
124- Color .hsl(hue = hue, saturation = saturation, lightness = 0.8f ),
125- Color .hsl(hue = hue, saturation = saturation, lightness = 0.7f ),
126- Color .hsl(hue = hue, saturation = saturation, lightness = 0.6f ),
127- Color .hsl(hue = hue, saturation = saturation, lightness = 0.5f ),
128- Color .hsl(hue = hue, saturation = saturation, lightness = 0.4f ),
129- Color .hsl(hue = hue, saturation = saturation, lightness = 0.3f ),
130- Color .hsl(hue = hue, saturation = saturation, lightness = 0.2f ),
131- Color .hsl(hue = hue, saturation = saturation, lightness = 0.1f )
132- )
117+ val colorList = mutableListOf<Color >()
118+ val reviseColorCount = ColorUtil .validateAndReviseColorCount(colorCount)
119+
120+ for (i in reviseColorCount downTo 1 ) {
121+ colorList.add(Color .hsl(hue = hue, saturation = saturation, lightness = ((1f / colorCount)* i)))
122+ }
123+ return colorList
133124 }
134125
135126 /* *
0 commit comments