Python code conversion to processing Java

Thank you so much for your effort. This helps a lot.

This is such a clever little piece of code.

So can I say that in the python code the first 7 lines are one function. I pop in an r,g,b and get a hue, a perceived luminosity and a value ?
Does repetitions go up ? What does it do ?

Then I use this function in stead of the normal sorting and say I want 8 steps.
How does python know where red starts and purple ends in hsv ?

My brain is exploding. This shortening in python is tricky.