# File lib/color/palette/monocontrast.rb, line 134
134:   def calculate_foreground(background, foreground)
135:     nfg = nil
136:       # Loop through brighter and darker versions of the foreground color.
137:       # The numbers here represent the amount of foreground color to mix
138:       # with black and white.
139:     [100, 75, 50, 25, 0].each do |percent|
140:       dfg = foreground.darken_by(percent)
141:       lfg = foreground.lighten_by(percent)
142: 
143:       dbd = brightness_diff(background, dfg)
144:       lbd = brightness_diff(background, lfg)
145: 
146:       if lbd > dbd
147:         nfg = lfg
148:         nbd = lbd
149:       else
150:         nfg = dfg
151:         nbd = dbd
152:       end
153: 
154:       ncd = color_diff(background, nfg)
155: 
156:       break if nbd >= @minimum_brightness_diff and ncd >= @minimum_color_diff
157:     end
158:     nfg
159:   end