Sha256: 64c66d2cc8df71f241e060c02f190bc6b5e17764134e5097f6d3b470cd112c7f

Contents?: true

Size: 1.06 KB

Versions: 109

Compression:

Stored size: 1.06 KB

Contents

# A colour object representing YIQ (NTSC) colour encoding.
class Color::YIQ
  include Color

  # Creates a YIQ colour object from fractional values 0 .. 1.
  #
  #   Color::YIQ.new(0.3, 0.2, 0.1)
  def self.from_fraction(y = 0, i = 0, q = 0, &block)
    new(y, i, q, 1.0, &block)
  end

  # Creates a YIQ colour object from percentages 0 .. 100.
  #
  #   Color::YIQ.new(10, 20, 30)
  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

  def coerce(other)
    other.to_yiq
  end

  def to_yiq
    self
  end

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

  def y
    @y
  end
  def y=(yy)
    @y = Color.normalize(yy)
  end
  def i
    @i
  end
  def i=(ii)
    @i = Color.normalize(ii)
  end
  def q
    @q
  end
  def q=(qq)
    @q = Color.normalize(qq)
  end

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

  def to_a
    [ y, i, q ]
  end
end

Version data entries

109 entries across 109 versions & 2 rubygems

Version Path
atome-0.5.6.5.7 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.6.5.6 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.6.5.4 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.6.5.1 lib/atome/helpers/color_helper/color/yiq.rb
atome-0.5.6.4.8 lib/atome/helpers/color_helper/color/yiq.rb
atome-0.5.6.4.5 lib/atome/helpers/color_helper/color/yiq.rb
atome-0.5.6.4.2 lib/atome/helpers/color_helper/color/yiq.rb
atome-0.5.6.4.1 lib/atome/helpers/color_helper/color/yiq.rb
atome-0.5.6.4.0 lib/atome/helpers/color_helper/color/yiq.rb
atome-0.5.6.3.9 lib/atome/helpers/color_helper/color/yiq.rb
atome-0.5.6.3.6 lib/atome/helpers/color_helper/color/yiq.rb
atome-0.5.6.3.5 lib/atome/helpers/color_helper/color/yiq.rb
atome-0.5.6.3.1 lib/atome/helpers/color_helper/color/yiq.rb
atome-0.5.6.3.0 lib/atome/helpers/color_helper/color/yiq.rb
atome-0.5.6.2.9 lib/atome/helpers/color_helper/color/yiq.rb
atome-0.5.6.2.7 lib/atome/helpers/color_helper/color/yiq.rb
atome-0.5.6.2.5 lib/atome/helpers/color_helper/color/yiq.rb
atome-0.5.6.2.4 lib/atome/helpers/color_helper/color/yiq.rb
atome-0.5.6.2.3 lib/atome/helpers/color_helper/color/yiq.rb
atome-0.5.6.2.1 lib/atome/helpers/color_helper/color/yiq.rb