class Color::YIQ
A Color object representing YIQ (NTSC) color encoding, where Y is the luma (brightness) value, and I (orange-blue) and Q (purple-green) are chrominance.
All values are clamped between 0 and 1 inclusive.
More more details, see YIQ.
YIQ colors are immutable Data class instances. Array deconstruction is [y, i, q] and hash deconstruction is {y:, i:, q:} (see y, i, q).
YIQ is only partially implemented: other Color objects can only be converted to YIQ, but it has few conversion functions for converting from YIQ.
Attributes
The i (orange-blue chrominance) attribute of this YIQ color expressed as a value 0..1.
The q (purple-green chrominance) attribute of this YIQ color expressed as a value 0..1.
The y (luma) attribute of this YIQ color expressed as a value 0..1.
Public Class Methods
Source
# File lib/color/yiq.rb, line 43 def self.from_percentage(*args, **kwargs) y, i, q = case [args, kwargs] in [[_, _, _], {}] args in [[], {y:, i:, q:}] [y, i, q] else new(*args, **kwargs) end new(y: y / 100.0, i: i / 100.0, q: q / 100.0) end
Creates a YIQ color object from percentage values 0 .. 1.
Color::YIQ.from_percentage(30, 20, 10) # => YIQ [30% 20% 10%] Color::YIQ.from_percentage(y: 30, i: 20, q: 10) # => YIQ [30% 20% 10%] Color::YIQ.from_values(30, 20, 10) # => YIQ [30% 20% 10%] Color::YIQ.from_values(y: 30, i: 20, q: 10) # => YIQ [30% 20% 10%]
Public Instance Methods
Source
# File lib/color/yiq.rb, line 77 def coerce(other) = other.to_yiq ## def to_yiq = self ## # Convert \YIQ to Color::Grayscale using the luma (#y) value. def to_grayscale = Color::Grayscale.from_fraction(y) ## alias_method :brightness, :y def inspect = "YIQ [%.2f%% %.2f%% %.2f%%]" % [y * 100, i * 100, q * 100] # :nodoc: def pretty_print(q) # :nodoc: q.text "YIQ" q.breakable q.group 2, "[", "]" do q.text "%.2f%%" % y q.fill_breakable q.text "%.2f%%" % i q.fill_breakable q.text "%.2f%%" % q end end alias_method :to_a, :deconstruct # :nodoc: alias_method :to_internal, :deconstruct # :nodoc: def deconstruct_keys(_keys) = {y:,
Coerces the other Color object into YIQ.
Source
# File lib/color/yiq.rb, line 84 def to_grayscale = Color::Grayscale.from_fraction(y) ## alias_method :brightness, :y def inspect = "YIQ [%.2f%% %.2f%% %.2f%%]" % [y * 100, i * 100, q * 100] # :nodoc: def pretty_print(q) # :nodoc: q.text "YIQ" q.breakable q.group 2, "[", "]" do q.text "%.2f%%" % y q.fill_breakable q.text "%.2f%%" % i q.fill_breakable q.text "%.2f%%" % q end end alias_method :to_a, :deconstruct # :nodoc: alias_method :to_internal, :deconstruct # :nodoc: def deconstruct_keys(_keys) = {y:, i:, q:
Convert YIQ to Color::Grayscale using the luma (y) value.
Source
# File lib/color/yiq.rb, line 80 def to_yiq = self ## # Convert \YIQ to Color::Grayscale using the luma (#y) value. def to_grayscale = Color::Grayscale.from_fraction(y) ## alias_method :brightness, :y def inspect = "YIQ [%.2f%% %.2f%% %.2f%%]" % [y * 100, i * 100, q * 100] # :nodoc: def pretty_print(q) # :nodoc: q.text "YIQ" q.breakable q.group 2, "[", "]" do q.text "%.2f%%" % y q.fill_breakable q.text "%.2f%%" % i q.fill_breakable q.text "%.2f%%" % q end end alias_method :to_a, :deconstruct # :nodoc: alias_method :to_internal, :deconstruct # :nodoc: def deconstruct_keys(_keys) = {y:, i:,