Class: ZPNG::Color

Inherits:
Struct
  • Object
show all
Defined in:
lib/zpng/color.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#aObject Also known as: alpha

Returns the value of attribute a

Returns:

  • (Object)

    the current value of a



2
3
4
# File 'lib/zpng/color.rb', line 2

def a
  @a
end

#bObject

Returns the value of attribute b

Returns:

  • (Object)

    the current value of b



2
3
4
# File 'lib/zpng/color.rb', line 2

def b
  @b
end

#gObject

Returns the value of attribute g

Returns:

  • (Object)

    the current value of g



2
3
4
# File 'lib/zpng/color.rb', line 2

def g
  @g
end

#rObject

Returns the value of attribute r

Returns:

  • (Object)

    the current value of r



2
3
4
# File 'lib/zpng/color.rb', line 2

def r
  @r
end

Instance Method Details

#black?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/zpng/color.rb', line 13

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

#to_grayscaleObject



17
18
19
# File 'lib/zpng/color.rb', line 17

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

#to_sObject



21
22
23
# File 'lib/zpng/color.rb', line 21

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

#white?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/zpng/color.rb', line 9

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