def from_hex(hex_value, opacity = nil)
      base_color = case hex_value
        when HEX3_COLOR_REGEXP
          $1.gsub(/([0-9a-f])/i, '\1\1').hex << 8
        when HEX6_COLOR_REGEXP
          $1.hex << 8
        else
          raise ArgumentError, "Not a valid hex color notation: #{hex_value.inspect}!"
      end
      opacity ||= $2 ? $2.hex : 0xff
      base_color | opacity
    end
def from_hex(hex_value, opacity = nil)
      base_color = case hex_value
        when HEX3_COLOR_REGEXP
          $1.gsub(/([0-9a-f])/i, '\1\1').hex << 8
        when HEX6_COLOR_REGEXP
          $1.hex << 8
        else
          raise ArgumentError, "Not a valid hex color notation: #{hex_value.inspect}!"
      end
      opacity ||= $2 ? $2.hex : 0xff
      base_color | opacity
    end
Creates a color by converting it from a string in hex notation.

 It supports colors with (#rrggbbaa) or without (#rrggbb) alpha channel
 as well as the 3-digit short format (#rgb) for those without.
 Color strings may include the prefix "0x" or "#".

 @param [String] hex_value The color in hex notation.
 @param [Integer] opacity The opacity value for the color. Overrides any
    opacity value given in the hex value if given.
 @return [Integer] The color value.
 @raise [ArgumentError] if the value given is not a hex color notation.