Class: Color::YIQ
- Inherits:
-
Object
- Object
- Color::YIQ
- Defined in:
- lib/color/yiq.rb,
lib/color.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
Class Method Details
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.
42 43 44 45 46 47 48 |
# File 'lib/color/yiq.rb', line 42 def ==(other) other = other.to_yiq other.kind_of?(Color::YIQ) and ((@y - other.y).abs <= Color::COLOR_TOLERANCE) and ((@i - other.i).abs <= Color::COLOR_TOLERANCE) and ((@q - other.q).abs <= Color::COLOR_TOLERANCE) end |
#brightness ⇒ Object
54 55 56 |
# File 'lib/color/yiq.rb', line 54 def brightness @y end |
#i ⇒ Object
68 69 70 |
# File 'lib/color/yiq.rb', line 68 def i @i end |
#i=(ii) ⇒ Object
71 72 73 |
# File 'lib/color/yiq.rb', line 71 def i=(ii) @i = Color.normalize(ii) end |
#inspect ⇒ Object
81 82 83 |
# File 'lib/color/yiq.rb', line 81 def inspect "YIQ [%.2f%%, %.2f%%, %.2f%%]" % [ @y * 100, @i * 100, @q * 100 ] end |
#q ⇒ Object
74 75 76 |
# File 'lib/color/yiq.rb', line 74 def q @q end |
#q=(qq) ⇒ Object
77 78 79 |
# File 'lib/color/yiq.rb', line 77 def q=(qq) @q = Color.normalize(qq) end |
#to_grayscale ⇒ Object Also known as: to_greyscale
57 58 59 |
# File 'lib/color/yiq.rb', line 57 def to_grayscale Color::GrayScale.new(@y) end |
#to_yiq ⇒ Object
50 51 52 |
# File 'lib/color/yiq.rb', line 50 def to_yiq self end |
#y ⇒ Object
62 63 64 |
# File 'lib/color/yiq.rb', line 62 def y @y end |