I have tried to find a good formula in Python 3 to calculate the complementary colour of a rgb code eg. complementary of a = b. Is there any way to do this?
r,g,b = [25,25,25]
def get_complementary(color):
color = color[1:]
color = int(color, 16)
comp_color = 0xFFFFFF ^ color
comp_color = "#%06X" % comp_color
return comp_color
hex_val = "#%02x%02x%02x" % (r,g,b)
h = get_complementary(hex_val)
print("Complementary color",h)
h = h.lstrip('#')
print('RGB =', tuple(int(h[i:i+2], 16) for i in (0, 2, 4)))
output:
Complementary color #E6E6E6
RGB = (230, 230, 230)