Module: Rszr::Color

Defined in:
lib/rszr/color.rb,
lib/rszr/color/base.rb,
lib/rszr/color/cmya.rb,
lib/rszr/color/rgba.rb,
lib/rszr/color/point.rb,
lib/rszr/color/gradient.rb

Defined Under Namespace

Classes: Base, CMYA, Gradient, Point, RGBA

Constant Summary collapse

Transparent =
RGBA.new(0, 0, 0, 0)
White =
RGBA.new(255,255,255)
Black =
RGBA.new(0, 0, 0)

Class Method Summary collapse

Class Method Details

.hex(str) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rszr/color/rgba.rb', line 9

def hex(str)
  str = str[1..-1] if str.start_with?('#')
  case str.size
  when 3, 4 then hex(str.chars.map { |c| c * 2 }.join)
  when 6 then hex("#{str}ff")
  when 8
    rgba(*str.scan(/../).map(&:hex))
  else
    raise ArgumentError, 'invalid color code'
  end
end

.rgba(red, green, blue, alpha = 255) ⇒ Object



5
6
7
# File 'lib/rszr/color/rgba.rb', line 5

def rgba(red, green, blue, alpha = 255)
  RGBA.new(red, green, blue, alpha)
end