Sha256: ad9f36d197b3d7342fb66c4560bb548f198fb1bae9e93880afc3de75882dd1e1

Contents?: true

Size: 383 Bytes

Versions: 2

Compression:

Stored size: 383 Bytes

Contents

module ZPNG
  class Color < Struct.new(:r,:g,:b,:a)

    alias :alpha :a

    BLACK = Color.new(0,0,0,0xff)
    WHITE = Color.new(0xff,0xff,0xff,0xff)

    def white?
      r == 0xff && g == 0xff && b == 0xff
    end

    def black?
      r == 0 && g == 0 && b == 0
    end

    def to_grayscale
      (r+g+b)/3
    end

    def to_s
      "%02X%02X%02X" % [r,g,b]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zpng-0.0.2 lib/zpng/color.rb
zpng-0.0.1 lib/zpng/color.rb