Skip to content

Instantly share code, notes, and snippets.

@ahmetabdi
Last active February 20, 2016 22:39
Show Gist options
  • Save ahmetabdi/13337e6833d4d5b8ae0f to your computer and use it in GitHub Desktop.
Save ahmetabdi/13337e6833d4d5b8ae0f to your computer and use it in GitHub Desktop.
Calculates the difference between two RGB Colour Values using Euclidean distance algorithm
r1 = 1.0
r2 = 0.95
g1 = 1.0
g2 = 1.0
b1 = 0.2
b2 = 0.1
# Euclidean distance
# The smaller the value of d2, the closer the colors (r1,g1,b1)and(r2,g2,b2) are to each other.
d2 = (30*(r1-r2))**2 + (59*(g1-g2))**2 + (11*(b1-b2))**2
puts d2
=> 3.4600000000000044
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment