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.7.6.0 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.7.5.9 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.7.5.4 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.7.5.3 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.7.5.1 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.7.4.8 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.7.4.7 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.7.4.6 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.7.4.3 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.7.4.2 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.7.3.9 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.7.3.6 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.7.3.5 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.7.3.3 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.7.3.2 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.7.3.1 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.7.3.0 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.7.1.8 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.7.1.7 lib/atome/utilities/color_helper/color/yiq.rb
atome-0.5.7.1.0 lib/atome/utilities/color_helper/color/yiq.rb