Colour Difference Formula

color-wheel-12-colors

RGB Colour Codes

Did you know that every colour on the screen can be represented using an RGB code (Red, Green, Blue) code. This code consists of three numbers between 0 and 255, indicating how much red, green and blue are used to recreate the colour. For instance the RGB code for:

  • Red is (255,0,0)
  • Green is (0,255,0)
  • Blue is (0,0,255)
  • Yellow is (255,255,0)
  • Orange is (255,165,0)

Graphic designer and software programmer sometimes prefer to use another notation based on hexadecimal RGB code where each of the three decimal values are converted into a two-digit hexadecimal code, resulting in a 6-digit (3×2) hexadecimal code. For instance:

  • Red is #FF000
  • Green is #00FF00
  • Blue is #0000FF
  • Yellow is #FFFF00
  • Orange is #FFA500

Check the following RGB Color picker to see how RGB codes work:

Using the RGB colour code we can represent 2563 = 16,777,216 colours.

Colour Wheel


A colour wheel is used to represent some of the most distinct colours. For instance the picture above represents a colour wheel that includes 12 colours:

RED (Hex: #FF0000 – RGB: 255, 0, 0)
ORANGE (Hex: #FF7F00 – RGB: 255, 127, 0)
YELLOW (Hex: #FFFF00 – RGB: 255, 255, 0)
CHARTREUSE GREEN (Hex: #7FFF00 – RGB: 127, 255, 0)
GREEN (Hex: #00FF00 – RGB: 0, 255, 0)
SPRING GREEN (Hex: #00FF7F – RGB: 0, 255, 127)
CYAN (Hex: #00FFFF – RGB: 0, 255, 255)
AZURE (Hex: #007FFF – RGB: 0, 127, 255)
BLUE (Hex: #0000FF – RGB: 0, 0, 255)
VIOLET (Hex: #7F00FF – RGB: 127, 0, 255)
MAGENTA (Hex: #FF00FF – RGB: 255, 0, 255)
ROSE (Hex: #FF007F – RGB: 255, 0, 127)

Colour Difference Formula


The colour difference formula is used to find out the “distance” between two colours:
color-difference-formula

We can use this formula to find out if two colours are very close (small difference).

Python Challenge


For this challenge, your task is to write a Python script that will:

  1. ask the user to input an RGB colour code,
  2. calculate the differences between this colour and each of the 12 colours of the above colour wheel,
  3. output the name of the closest colour from the colour wheel. (The colour with the smallest difference)

Test Plan


Once your code is done, complete the following tests to check that your code is working as it should:

Test # Input Values /Colour Code Expected Output Actual Output
#1 (222, 215, 21) Yellow
#2 (201, 45, 139) Rose
#3 (124, 180, 48) Charteuse Green
#4 (36, 180, 225) Azure
#5 (100, 50, 150) Violet
#6 (200, 100, 50) Orange
Share Button