Check the difference (or similarity) between two colors in your game using the CIE94 formula.

This script checks two color values (provided as arguments in standard GM format) and returns the color difference as a numerical value. The closer to zero the value is, the more alike the colors are.

How does it work?

The script is used as follows:

colors_compare_cie94( color_one, color_two );

The script gets the RGB values of the two colors and converts them to XYZ values and then to Lab values.
Then, the CIE94 formula is used to find the value of Delta-E (94), the difference between the two colors.

You can find out more about the CIE94 formula here: Wikipedia

Why is this useful?

There are many different applications of this script that could be useful. You could use the returned value to check how well your character blends into the background of your level (for stealth games) or you could use it to create a “green screen” effect. You could also use this value to make your games more friendly to users with vision problems. Let your imagination run wild?

Is it 100% foolproof?

Unfortunately, no. Mathematically calculating the similarity between two colors is no substitute for a healthy human eye. CIE94 isn’t perfect. You may notice various areas where more similar colors, as perceived by our eyes, are given an ‘odd’ rating by the formula. This is unfortunately unavoidable.

$1.99 on GameMaker: Marketplace

Written by Dan

Managing Director and mobile development whizz.