def whichBall(color): minIndex = None minSoFar = maxint for i in range(10): diff = col_diff(color, BALLS_COLOR[i]) if diff < minSoFar: minSoFar = diff minIndex = i if minSoFar > 30: pass #print "Warning: > 30, might not be right!", minSoFar return minIndex
def is_cue_color(color, tolerance = 100): """ Return whether this color is cue's color. """ return col_diff(color, CUE_COLOR) <= tolerance
def same(color1, color2, tolerance=50): """Are the two near the same?""" return col_diff(color1, color2) < tolerance