Untitled
unknown
plain_text
2 years ago
596 B
5
Indexable
def approximate_color_name(rgb): color_ranges = { "Yellow": ((150, 150, 0), (255, 255, 50)), "Black": ((0, 0, 0), (50, 50, 50)), "White": ((200, 200, 200), (255, 255, 255)), "Blue": ((0, 0, 150), (50, 50, 255)), "Red": ((150, 0, 0), (255, 50, 50)), } for color, (lower, upper) in color_ranges.items(): if all(lower[i] <= rgb[i] <= upper[i] for i in range(3)): return color return "Unknown" # Example usage: rgb_value = (220, 220, 0) color_name = approximate_color_name(rgb_value) print(color_name)
Editor is loading...