Given a threshold and a collection of colors, you'll be able to determine how close a given color is to matching a list.
require 'color-proximity' cp = ColorProximity.new(0.5, ['000000']) cp.past_threshold?('000000') # [false, ['000000']] cp.collection = ['ffffff']) cp.past_threshold?('000000') # [true] cp.collection = ['000001', '000002', 'ffffff']) cp.thresholds('000003') # [3.3166247903554, 1.4142135623730951, 762.3437544835007]
A failure case returns an array with two elements:
false, and the collection of colors that failed the threshold. Success cases return an array with one element:
true. This is designed to make it easy to call
.first on the result to validate it.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install color-proximity