Class: Color

Inherits:
Gosu::Color
  • Object
show all
Defined in:
lib/fantasy/color.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r:, g:, b:, a: 255, name: nil) ⇒ Color

Returns a new instance of Color.



8
9
10
11
12
13
14
15
16
# File 'lib/fantasy/color.rb', line 8

def initialize(r:, g:, b:, a: 255, name: nil)
  super(a, r, g, b)

  @a = a
  @r = r
  @g = g
  @b = b
  @name = name
end

Class Attribute Details

.paletteObject (readonly)

Returns the value of attribute palette.



32
33
34
# File 'lib/fantasy/color.rb', line 32

def palette
  @palette
end

Instance Attribute Details

#aObject (readonly)

Returns the value of attribute a.



6
7
8
# File 'lib/fantasy/color.rb', line 6

def a
  @a
end

#bObject (readonly)

Returns the value of attribute b.



6
7
8
# File 'lib/fantasy/color.rb', line 6

def b
  @b
end

#gObject (readonly)

Returns the value of attribute g.



6
7
8
# File 'lib/fantasy/color.rb', line 6

def g
  @g
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/fantasy/color.rb', line 6

def name
  @name
end

#rObject (readonly)

Returns the value of attribute r.



6
7
8
# File 'lib/fantasy/color.rb', line 6

def r
  @r
end

Instance Method Details

#hexObject



18
19
20
21
22
# File 'lib/fantasy/color.rb', line 18

def hex
  [@r, @g, @b].map do |e|
    e.to_s(16).rjust(2, "0")
  end.join
end

#to_sObject



24
25
26
27
28
29
# File 'lib/fantasy/color.rb', line 24

def to_s
  result = "r:#{@r}, g:#{@g}, b:#{@b}, a:#{@a}, hex:#{hex}"
  result += " (#{name})" unless name.nil?

  result
end