Class: Savio::RgbColor

Inherits:
Struct
  • Object
show all
Defined in:
lib/savio/hsv2rgb.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bObject

Returns the value of attribute b

Returns:

  • (Object)

    the current value of b



2
3
4
# File 'lib/savio/hsv2rgb.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/savio/hsv2rgb.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/savio/hsv2rgb.rb', line 2

def r
  @r
end

Class Method Details

.newFromHSV(hsv) ⇒ Object



3
4
5
6
# File 'lib/savio/hsv2rgb.rb', line 3

def self.newFromHSV(hsv)
  rgb = hsv.to_rgb()
  return RgbColor.new(rgb.r,rgb.g,rgb.b)
end

Instance Method Details

#to_hsvObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/savio/hsv2rgb.rb', line 7

def to_hsv()
  max = [r, g, b].max
  min = [r, g, b].min
  delta = max - min
  v = max

  if (max != 0.0)
    s = delta / max
  else
    s = 0.0
  end

  if (s == 0.0)
    h = 0.0
  else
    if (r == max)
      h = 0 + (g - b) / delta
    elsif (g == max)
      h = 2 + (b - r) / delta
    elsif (b == max)
      h = 4 + (r - g) / delta
    end

    h *= 60.0

    if (h < 0)
      h += 360.0
    end
  end
  return HsvColor.new(h,s,v)
end