I went looking through Raphael.js\'s source code to find out how he converted RGB values to HSB. I found out the function he did it in and I was in the process
Raphael.js
Why not use ternary operators found in Python?
H = ( None if C == 0 else (g - b) / C if V == r else (b - r) / C + 2 if V == g else (r - g) / C + 4 )