I am trying to set certain values for variables. The variables are for determining if a hex colour is green, red, blue, OR green and red, blue and red, or green and blue.
The value I am trying to set to determine if something is green and red vs just red or just green is to have a certain number range, in which something would be qualified as green AND red, etc…
E.G: FF0000 = Red. A1A100 = Red and Green, A1C124 = Red and Green.
My A1C124 code would have problems in my script, because it is difficult to just say
if
Red > Green or \
Red = Green and \
Red > Blue
print red and green.
Because if that code were to run, anything that is clearly red would also come out as green and red.
So instead, I am trying to set a limit to how greater than green can red be, and vice-versa. And for that to happen, I need to set a range.
Something along the lines of:
redGreen = green +1
redGreen2 = green -1
redGreen3 = green + 2
redGreen4 = green - 2
And then I would set the code kind of like this:
if red > blue and \
green > blue:
redGreen = green +1
redGreen2 = green -1
redGreen3 = green + 2
redGreen4 = green - 2
print "This colour is red and green"
But there are 2 problems.
The above code does not work, as it just replaces the + 1 with the +2, and same for the negative values, and I for the life of me cannot understand any tutorials that teach me this.
So, does anyone know how to set a range? Or if there is a better method, can you explain what it is please?
Admittedly, I did not manage to follow your post completely. There’s a chance, though, that converting the colour in question to HSV space and looking at the hue value only will simplify what you are trying to do.
Python provides the function
colorsys.rgb_to_hsv()to perform this conversion.