Class: Color::YIQ

Inherits:
Object
  • Object
show all
Defined in:
lib/color/yiq.rb,
lib/color.rb

Overview

A colour object representing YIQ (NTSC) colour encoding.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(y = 0, i = 0, q = 0) ⇒ YIQ

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

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


31
32
33
34
35
# File 'lib/color/yiq.rb', line 31

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.

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


20
21
22
23
24
25
26
# File 'lib/color/yiq.rb', line 20

def self.from_fraction(y = 0, i = 0, q = 0)
  color = Color::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.



44
45
46
47
48
49
50
# File 'lib/color/yiq.rb', line 44

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

#brightnessObject



56
57
58
# File 'lib/color/yiq.rb', line 56

def brightness
  @y
end

#iObject



70
71
72
# File 'lib/color/yiq.rb', line 70

def i
  @i
end

#i=(ii) ⇒ Object



73
74
75
# File 'lib/color/yiq.rb', line 73

def i=(ii)
  @i = Color.normalize(ii)
end

#inspectObject



83
84
85
# File 'lib/color/yiq.rb', line 83

def inspect
  "YIQ [%.2f%%, %.2f%%, %.2f%%]" % [ @y * 100, @i * 100, @q * 100 ]
end

#qObject



76
77
78
# File 'lib/color/yiq.rb', line 76

def q
  @q
end

#q=(qq) ⇒ Object



79
80
81
# File 'lib/color/yiq.rb', line 79

def q=(qq)
  @q = Color.normalize(qq)
end

#to_grayscaleObject Also known as: to_greyscale



59
60
61
# File 'lib/color/yiq.rb', line 59

def to_grayscale
  Color::GrayScale.new(@y)
end

#to_yiqObject



52
53
54
# File 'lib/color/yiq.rb', line 52

def to_yiq
  self
end

#yObject



64
65
66
# File 'lib/color/yiq.rb', line 64

def y
  @y
end

#y=(yy) ⇒ Object



67
68
69
# File 'lib/color/yiq.rb', line 67

def y=(yy)
  @y = Color.normalize(yy)
end