Colors that are opposite to each other on the color wheel are called complementary colors. You can look out on web for more information.

The function below takes a color as a input (hex-value) and returns its complementary color (hex-value).
def get_complementary(color):
# strip the # from the beginning
color = color[1:]
# convert the string into hex
color = int(color, 16)
# invert the three bytes
# as good as substracting each of RGB component by 255(FF)
comp_color = 0xFFFFFF ^ color
# convert the color back to hex by prefixing a #
comp_color = "#%06X" % comp_color
# return the result
return comp_color
Hi, thanks for publishing this “Complementary Colors – Python Code”; are you proving it under an Open Source license such as the MIT license?
LikeLike
If for use, you can use it!
LikeLike
Thanks a lot !
LikeLike