Module: ColorContrastCalc::ThresholdFinder::Brightness
- Extended by:
- FinderUtils
- Defined in:
- lib/color_contrast_calc/threshold_finder.rb
Overview
Module that implements the main logic of the instance method Color#find_brightness_threshold().
Class Method Summary collapse
-
.find(fixed_rgb, other_rgb, level = Checker::Level::AA) ⇒ Array<Integer>
Try to find a color who has a satisfying contrast ratio.
Class Method Details
.find(fixed_rgb, other_rgb, level = Checker::Level::AA) ⇒ Array<Integer>
Try to find a color who has a satisfying contrast ratio.
The color returned by this method will be created by changing the brightness of other_rgb
. Even when a color that satisfies the specified level is not found, the method returns a new color anyway.
169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/color_contrast_calc/threshold_finder.rb', line 169 def self.find(fixed_rgb, other_rgb, level = Checker::Level::AA) criteria = Criteria.define(level, fixed_rgb, other_rgb) w = calc_upper_ratio_limit(other_rgb) / 2.0 upper_rgb = upper_limit_rgb(criteria, other_rgb, w * 2) return upper_rgb if upper_rgb last_r, passing_r = find_ratio(other_rgb, criteria, w, w).map do |ratio| criteria.round(ratio) if ratio end rgb_with_better_ratio(other_rgb, criteria, last_r, passing_r) end |