Class Color::YIQ
In: lib/color.rb
lib/color/yiq.rb
Parent: Object
Enumerable Gimp AdobeColor CMYK\n[lib/color.rb\nlib/color/cmyk.rb] GrayScale\n[lib/color.rb\nlib/color/grayscale.rb] RGB\n[lib/color.rb\nlib/color/rgb-colors.rb\nlib/color/rgb.rb] YIQ\n[lib/color.rb\nlib/color/yiq.rb] HSL MonoContrast lib/color/cmyk.rb lib/color/grayscale.rb lib/color/rgb.rb lib/color/yiq.rb lib/color/hsl.rb CSS lib/color/palette/gimp.rb lib/color/palette/adobecolor.rb lib/color/palette/monocontrast.rb Palette Color dot/m_10_0.png

A colour object representing YIQ (NTSC) colour encoding.

Methods

==   brightness   from_fraction   i   i=   inspect   new   q   q=   to_grayscale   to_greyscale   to_yiq   y   y=  

Public Class methods

Creates a YIQ colour object from fractional values 0 .. 1.

  Color::YIQ.new(0.3, 0.2, 0.1)

[Source]

    # File lib/color/yiq.rb, line 20
20:   def self.from_fraction(y = 0, i = 0, q = 0)
21:     color = Color::YIQ.new
22:     color.y = y
23:     color.i = i
24:     color.q = q
25:     color
26:   end

Creates a YIQ colour object from percentages 0 .. 100.

  Color::YIQ.new(10, 20, 30)

[Source]

    # File lib/color/yiq.rb, line 31
31:   def initialize(y = 0, i = 0, q = 0)
32:     @y = y / 100.0
33:     @i = i / 100.0
34:     @q = q / 100.0
35:   end

Public Instance methods

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.

[Source]

    # File lib/color/yiq.rb, line 44
44:   def ==(other)
45:     other = other.to_yiq
46:     other.kind_of?(Color::YIQ) and
47:     ((@y - other.y).abs <= Color::COLOR_TOLERANCE) and
48:     ((@i - other.i).abs <= Color::COLOR_TOLERANCE) and
49:     ((@q - other.q).abs <= Color::COLOR_TOLERANCE) 
50:   end

[Source]

    # File lib/color/yiq.rb, line 56
56:   def brightness
57:     @y
58:   end

[Source]

    # File lib/color/yiq.rb, line 70
70:   def i
71:     @i
72:   end

[Source]

    # File lib/color/yiq.rb, line 73
73:   def i=(ii)
74:     @i = Color.normalize(ii)
75:   end

[Source]

    # File lib/color/yiq.rb, line 83
83:   def inspect
84:     "YIQ [%.2f%%, %.2f%%, %.2f%%]" % [ @y * 100, @i * 100, @q * 100 ]
85:   end

[Source]

    # File lib/color/yiq.rb, line 76
76:   def q
77:     @q
78:   end

[Source]

    # File lib/color/yiq.rb, line 79
79:   def q=(qq)
80:     @q = Color.normalize(qq)
81:   end

[Source]

    # File lib/color/yiq.rb, line 59
59:   def to_grayscale
60:     Color::GrayScale.new(@y)
61:   end
to_greyscale()

Alias for to_grayscale

[Source]

    # File lib/color/yiq.rb, line 52
52:   def to_yiq
53:     self
54:   end

[Source]

    # File lib/color/yiq.rb, line 64
64:   def y
65:     @y
66:   end

[Source]

    # File lib/color/yiq.rb, line 67
67:   def y=(yy)
68:     @y = Color.normalize(yy)
69:   end

[Validate]