Class: ColorLib::YIQ
- Inherits:
-
Object
- Object
- ColorLib::YIQ
- Defined in:
- lib/color_lib/yiq.rb,
lib/color_lib.rb
Overview
A colour object representing YIQ (NTSC) colour encoding.
Class Method Summary collapse
-
.from_fraction(y = 0, i = 0, q = 0) ⇒ Object
Creates a YIQ colour object from fractional values 0 ..
Instance Method Summary collapse
-
#==(other) ⇒ Object
Compares the other colour to this one.
- #brightness ⇒ Object
- #i ⇒ Object
- #i=(ii) ⇒ Object
-
#initialize(y = 0, i = 0, q = 0) ⇒ YIQ
constructor
Creates a YIQ colour object from percentages 0 ..
- #inspect ⇒ Object
- #q ⇒ Object
- #q=(qq) ⇒ Object
- #to_grayscale ⇒ Object (also: #to_greyscale)
- #to_yiq ⇒ Object
- #y ⇒ Object
- #y=(yy) ⇒ Object
Constructor Details
#initialize(y = 0, i = 0, q = 0) ⇒ YIQ
Creates a YIQ colour object from percentages 0 .. 100.
ColorLib::YIQ.new(10, 20, 30)
17 18 19 20 21 |
# File 'lib/color_lib/yiq.rb', line 17 def initialize(y = 0, i = 0, q = 0) @y = y / 100.0 @i = i / 100.0 @q = q / 100.0 end |
Class Method Details
.from_fraction(y = 0, i = 0, q = 0) ⇒ Object
Creates a YIQ colour object from fractional values 0 .. 1.
ColorLib::YIQ.new(0.3, 0.2, 0.1)
6 7 8 9 10 11 12 |
# File 'lib/color_lib/yiq.rb', line 6 def self.from_fraction(y = 0, i = 0, q = 0) color = ColorLib::YIQ.new color.y = y color.i = i color.q = q color end |
Instance Method Details
#==(other) ⇒ Object
Compares the other colour to this one. The other colour will be converted to YIQ before comparison, so the comparison between a YIQ colour and a non-YIQ colour will be approximate and based on the other colour’s #to_yiq conversion. If there is no #to_yiq conversion, this will raise an exception. This will report that two YIQ values are equivalent if all component colours are within COLOR_TOLERANCE of each other.
30 31 32 33 34 35 36 |
# File 'lib/color_lib/yiq.rb', line 30 def ==(other) other = other.to_yiq other.kind_of?(ColorLib::YIQ) and ((@y - other.y).abs <= ColorLib::COLOR_TOLERANCE) and ((@i - other.i).abs <= ColorLib::COLOR_TOLERANCE) and ((@q - other.q).abs <= ColorLib::COLOR_TOLERANCE) end |
#brightness ⇒ Object
42 43 44 |
# File 'lib/color_lib/yiq.rb', line 42 def brightness @y end |
#i ⇒ Object
60 61 62 |
# File 'lib/color_lib/yiq.rb', line 60 def i @i end |
#i=(ii) ⇒ Object
64 65 66 |
# File 'lib/color_lib/yiq.rb', line 64 def i=(ii) @i = ColorLib.normalize(ii) end |
#inspect ⇒ Object
76 77 78 |
# File 'lib/color_lib/yiq.rb', line 76 def inspect "YIQ [%.2f%%, %.2f%%, %.2f%%]" % [@y * 100, @i * 100, @q * 100] end |
#q ⇒ Object
68 69 70 |
# File 'lib/color_lib/yiq.rb', line 68 def q @q end |
#q=(qq) ⇒ Object
72 73 74 |
# File 'lib/color_lib/yiq.rb', line 72 def q=(qq) @q = ColorLib.normalize(qq) end |
#to_grayscale ⇒ Object Also known as: to_greyscale
46 47 48 |
# File 'lib/color_lib/yiq.rb', line 46 def to_grayscale ColorLib::GrayScale.new(@y) end |
#to_yiq ⇒ Object
38 39 40 |
# File 'lib/color_lib/yiq.rb', line 38 def to_yiq self end |
#y ⇒ Object
52 53 54 |
# File 'lib/color_lib/yiq.rb', line 52 def y @y end |
#y=(yy) ⇒ Object
56 57 58 |
# File 'lib/color_lib/yiq.rb', line 56 def y=(yy) @y = ColorLib.normalize(yy) end |