Module: Sai::Conversion::RGB::ColorClassifier Private
- Defined in:
- lib/sai/conversion/rgb/color_classifier.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Classify color characteristics
Class Method Summary collapse
-
.closest_ansi_color(red, green, blue) ⇒ Symbol
private
Get closest ANSI color for RGB values.
-
.dark?(red, green, blue) ⇒ Boolean
private
Determine if a color is dark.
-
.grayscale?(red, green, blue) ⇒ Boolean
private
Determine if a color is grayscale.
-
.primary?(red, green, blue) ⇒ Boolean
private
Determine if RGB values represent a primary color.
-
.primary_color(red, green, blue) ⇒ Symbol
private
Get the closest primary color.
-
.secondary?(red, green, blue) ⇒ Boolean
private
Determine if RGB values represent a secondary color.
-
.secondary_color(red, green, blue) ⇒ Symbol
private
Get the closest secondary color.
Class Method Details
.closest_ansi_color(red, green, blue) ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get closest ANSI color for RGB values
27 28 29 30 31 32 33 34 |
# File 'lib/sai/conversion/rgb/color_classifier.rb', line 27 def closest_ansi_color(red, green, blue) return :black if dark?(red, green, blue) return :white if grayscale?(red, green, blue) return primary_color(red, green, blue) if primary?(red, green, blue) return secondary_color(red, green, blue) if secondary?(red, green, blue) :white end |
.dark?(red, green, blue) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determine if a color is dark
49 50 51 |
# File 'lib/sai/conversion/rgb/color_classifier.rb', line 49 def dark?(red, green, blue) [red, green, blue].max < 0.3 end |
.grayscale?(red, green, blue) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determine if a color is grayscale
66 67 68 |
# File 'lib/sai/conversion/rgb/color_classifier.rb', line 66 def grayscale?(red, green, blue) red == green && green == blue end |
.primary?(red, green, blue) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determine if RGB values represent a primary color
83 84 85 86 87 |
# File 'lib/sai/conversion/rgb/color_classifier.rb', line 83 def primary?(red, green, blue) max = [red, green, blue].max mid = [red, green, blue].sort[1] (max - mid) > 0.3 end |
.primary_color(red, green, blue) ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the closest primary color
102 103 104 105 106 107 108 109 |
# File 'lib/sai/conversion/rgb/color_classifier.rb', line 102 def primary_color(red, green, blue) max = [red, green, blue].max case max when red then :red when green then :green else :blue end end |
.secondary?(red, green, blue) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determine if RGB values represent a secondary color
124 125 126 127 128 129 130 |
# File 'lib/sai/conversion/rgb/color_classifier.rb', line 124 def secondary?(red, green, blue) return true if yellow?(red, green, blue) return true if magenta?(red, green, blue) return true if cyan?(red, green, blue) false end |
.secondary_color(red, green, blue) ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the closest secondary color
145 146 147 148 149 150 151 |
# File 'lib/sai/conversion/rgb/color_classifier.rb', line 145 def secondary_color(red, green, blue) return :yellow if yellow?(red, green, blue) return :magenta if magenta?(red, green, blue) return :cyan if cyan?(red, green, blue) :white end |