Sha256: c09c4ac932b4c8556b47c3c45d3722b8f64a73f8a142a1e3dd603d84059cf9c7

Contents?: true

Size: 979 Bytes

Versions: 1

Compression:

Stored size: 979 Bytes

Contents

require 'gosu'

class Gosu::Color
  # Provides the ability to adjust the opacity (alpha).
  # The opacity argument should be a float 0.0..1.0
  def opacity(opacity)
    hex_string = "0x%02x%02x%02x%02x" % [(opacity * 255), red, green, blue]
    self.class.argb(hex_string.to_i(16))
  end
end

module Rcade
  class Color < Gosu::Color

    # hex argument should be a string and can be the full 6 digit hex 
    # or 3 digit shorthand and may include a # prefix.
    # Examples:
    #   "fed"
    #   "#fed"
    #   "cabbed"
    #   "#cabbed"
    def self.from_hex(string)
      h = string.scan(/\h/)
      if h.size == 3
        h.map! {|v| (v * 2) } # expand to 6 character format
      end
      hex_string = "0xff" + h.join # fully opaque
      self.argb(hex_string.to_i(16))
    end

    def self.named(color_name)
      require 'color/css'
      color = ::Color::CSS[color_name]
      raise 'Invalid color name' unless color
      self.from_hex(color.html)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rcade_colors-0.0.6 lib/rcade_colors.rb