class Colour
Constants
- COLOURS
- Error
Attributes
triplet[R]
Public Class Methods
new(string_or_array)
click to toggle source
# File lib/nswtopo/helpers/colour.rb, line 154 def initialize(string_or_array) @triplet = case string_or_array when Array then string_or_array.take(3).map(&:round) when *COLOURS.keys @name = string_or_array COLOURS[string_or_array] when /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i [$1, $2, $3].map { |hex| Integer("0x#{hex}") } when /^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/ [$1, $2, $3].map(&:to_i) end raise Error, "invalid colour: #{string_or_array}" unless @triplet&.all?(0..255) end
Public Instance Methods
mix(other, fraction)
click to toggle source
# File lib/nswtopo/helpers/colour.rb, line 169 def mix(other, fraction) Colour.new [triplet, other.triplet].along(fraction.to_f).map(&:to_i) end
to_s()
click to toggle source
# File lib/nswtopo/helpers/colour.rb, line 173 def to_s @name || "#%.2X%.2X%.2X" % triplet end