Complementary Colours Algorithm

Complementary colors are pairs of colors which, when combined or mixed, cancel each other out by producing a grayscale color like white or black. When placed next to each other, they create the strongest contrast for those two colors. Complementary colors may also be called “opposite colors.”.

To find out pairs of complementary colours we can use a colour wheel. Colours which are at the opposite position on the colour wheel are complementary colours:
complementary-colours

Complementary Colours Formula


When representing colours using the RGB colour code, we can use the following formula to work out the complementary RGB colour code:
complementary-colour-formula

Complementary Colours Algorithm


Our aim is to write a Python program, based on the INPUT, PROCESS and OUTPUT model in order to:

  1. INPUT: Ask the user to enter an RGB colour code
  2. PROCESS: Apply the complementary colour code formula to work out the RGB code of the comlpementary colour
  3. OUPUT: Display the complementary colour code on screen

Our code will be based on the following flowchart:
complementary-colours-flowchart

Casting


To complete this challenge, you will need to understand the importance of casting values from string to integer data types using the int() function and from integer to string using the str() function.

Python Code


Share Button
Tagged with: