Class: Color::YIQ

Inherits:
Object show all
Includes:
Color
Defined in:
lib/atome/utilities/color_helper/color/yiq.rb,
lib/atome/utilities/color_helper/color.rb

Overview

A colour object representing YIQ (NTSC) colour encoding.

Constant Summary

Constants included from Color

COLOR_EPSILON, COLOR_TOLERANCE, COLOR_VERSION, GreyScale

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Color

#==, coerce, const_missing, equivalent?, #name, #names, #names=, near?, near_one?, near_one_or_more?, near_zero?, near_zero_or_less?, new, normalize, normalize_byte, normalize_to_range, normalize_word

Constructor Details

#initialize(y = 0, i = 0, q = 0, radix = 100.0, &block) ⇒ YIQ

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

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


15
16
17
18
# File 'lib/atome/utilities/color_helper/color/yiq.rb', line 15

def initialize(y = 0, i = 0, q = 0, radix = 100.0, &block) # :yields self:
  @y, @i, @q = [ y, i, q ].map { |v| Color.normalize(v / radix) }
  block.call if block
end

Class Method Details

.from_fraction(y = 0, i = 0, q = 0, &block) ⇒ Object

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

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


8
9
10
# File 'lib/atome/utilities/color_helper/color/yiq.rb', line 8

def self.from_fraction(y = 0, i = 0, q = 0, &block)
  new(y, i, q, 1.0, &block)
end

Instance Method Details

#brightnessObject



28
29
30
# File 'lib/atome/utilities/color_helper/color/yiq.rb', line 28

def brightness
  @y
end

#coerce(other) ⇒ Object



20
21
22
# File 'lib/atome/utilities/color_helper/color/yiq.rb', line 20

def coerce(other)
  other.to_yiq
end

#iObject



42
43
44
# File 'lib/atome/utilities/color_helper/color/yiq.rb', line 42

def i
  @i
end

#i=(ii) ⇒ Object



45
46
47
# File 'lib/atome/utilities/color_helper/color/yiq.rb', line 45

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

#inspectObject



55
56
57
# File 'lib/atome/utilities/color_helper/color/yiq.rb', line 55

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

#qObject



48
49
50
# File 'lib/atome/utilities/color_helper/color/yiq.rb', line 48

def q
  @q
end

#q=(qq) ⇒ Object



51
52
53
# File 'lib/atome/utilities/color_helper/color/yiq.rb', line 51

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

#to_aObject



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

def to_a
  [ y, i, q ]
end

#to_grayscaleObject Also known as: to_greyscale



31
32
33
# File 'lib/atome/utilities/color_helper/color/yiq.rb', line 31

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

#to_yiqObject



24
25
26
# File 'lib/atome/utilities/color_helper/color/yiq.rb', line 24

def to_yiq
  self
end

#yObject



36
37
38
# File 'lib/atome/utilities/color_helper/color/yiq.rb', line 36

def y
  @y
end

#y=(yy) ⇒ Object



39
40
41
# File 'lib/atome/utilities/color_helper/color/yiq.rb', line 39

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