kristiyanP/colorpicker

Suggestion: Easy "full-range"

glureau opened this issue · 2 comments

For my usage, the examples was not great because a lot of shading were not available in the examples, so I did my own color table. I'd just share a block of code I used to have a simple & efficient color panel. (It's in Kotlin but pretty easy to move to Java, will be happy to do it if you want to.)

Result:

image

Code:

private fun generateColors(width: Int, height: Int): IntArray {
    val colorCount = width * height
    val result = IntArray(colorCount)
    for (index in 0..colorCount - 1) {
        if (index % width == 0) {
            // White->Black
            val hsv = floatArrayOf(0f, 0f, (index / width) / (height - 1).toFloat())
            result[index] = Color.HSVToColor(hsv)
        } else {
            // All colors
            val hsv = floatArrayOf(
                    ((index % width) / (width - 1).toFloat()) * 360f,
                    Math.min(1f, 2f - ((index / width) + 1) / ((height + 1) / 2f)),
                    Math.min(1f, ((index / width) + 1) / ((height + 1) / 2f)))
            result[index] = Color.HSVToColor(hsv)
        }
    }
    return result
}

How to use it:

    colorPicker.setColors(*generateColors(10, 7))
    colorPicker.setColumns(10)

So maybe it could be interesting for the community?

yes it does have an interesting look, in the next release i will add a function to be able to set the shading
Thank you

Closing old issue. Have a nice day!