Python code conversion to processing Java

Thank you for you answer.
I would risk to use the processing internal conversion to HSB (hue,saturation, brightness). This should only give a different direction from light to dark. that would be fine.

What I really dont get at all is the line:

colours.sort(key=lambda (r,g,b): step(r,g,b,8) )

Is this a second loop, and a sorting depending on what ?
lambda seems to be a function for short time usage and is deleted after using ?

???