Revision as of 04:28, 7 April 2004 editChinasaur (talk | contribs)Extended confirmed users3,353 edits Did my best to touch things up for HSV. Dunno Py, so may need tweaking to get it to run.← Previous edit |
Revision as of 04:32, 7 April 2004 edit undoChinasaur (talk | contribs)Extended confirmed users3,353 editsm Changed all my added comments to "# -->" so you can find themNext edit → |
Line 30: |
Line 30: |
|
MIN=min(r,g,b) |
|
MIN=min(r,g,b) |
|
|
|
|
|
# Using negatives for this generally not a good idea. In most |
|
# --> Using negatives for this generally not a good idea. In most |
|
# languages, you'd want to use a special value like "undef" or |
|
# --> languages, you'd want to use a special value like "undef" or |
|
# "null". I think Python has "none" but I don't know Python so |
|
# --> "null". I think Python has "none" but I don't know Python so |
|
# I'm not sure if that's what you'd use. |
|
# --> I'm not sure if that's what you'd use. |
|
# Especially not a good idea in this case since h is actually supposed |
|
# --> Especially not a good idea in this case since h is actually |
|
# to be able to go negative (see below and my new revision to the |
|
# --> supposed to be able to go negative (see below and my new |
|
# HSV color space article. |
|
# --> revision to the HSV color space article. |
|
# And anyway, using the else statement is a better way to arrange the |
|
# --> And anyway, using the else statement is a better way to arrange |
|
# logic. Easier to read, and one less comparison so probably more |
|
# --> the logic; easier to read, and one less comparison so probably |
|
# efficient. |
|
# --> more efficient. |
|
# h=-1 |
|
# h=-1 |
|
# s=-1 |
|
# s=-1 |
Line 52: |
Line 52: |
|
if r == MAX: h=(0.0+( (g-b)/(MAX-MIN) ))*60 |
|
if r == MAX: h=(0.0+( (g-b)/(MAX-MIN) ))*60 |
|
|
|
|
|
# This was wrong in the article; reversed the minus |
|
# --> This was wrong in the article; reversed the minus |
|
if g == MAX: h=(2.0+( (b-r)/(MAX-MIN) ))*60 |
|
if g == MAX: h=(2.0+( (b-r)/(MAX-MIN) ))*60 |
|
if b == MAX: h=(4.0+( (r-g)/(MAX-MIN) ))*60 |
|
if b == MAX: h=(4.0+( (r-g)/(MAX-MIN) ))*60 |
|
# Actually h should be undefined in this case; you might want to |
|
# --> Actually h should be undefined in this case; you might want to |
|
# set it to "none" if that's the way Python works. In practice |
|
# --> set it to "none" if that's the way Python works. In practice |
|
# there's nothing wrong with making it zero though. |
|
# --> there's nothing wrong with making it zero though. |
|
else: h = 0 |
|
else: h = 0 |
|
|
|
|
Line 64: |
Line 64: |
|
V=int(v*100) |
|
V=int(v*100) |
|
|
|
|
|
# H will intentionally come out < 0 for purples; have to wrap around |
|
# --> H will intentionally come out < 0 for purples; have to wrap around |
|
# if H<0: H="undefined" |
|
# if H<0: H="undefined" |
|
if H < 0: H += 360 |
|
if H < 0: H += 360 |
|
|
|
|
|
# Shouldn't be possible for S < 0; at most throw an error here but |
|
# --> Shouldn't be possible for S < 0 anymore |
|
# I'd just cut it. |
|
|
# if S<0: S="undefined" |
|
# if S<0: S="undefined" |
|
|
|
|