Module: GrayScott::Color

Includes:
XumoShortHand
Included in:
Controller
Defined in:
lib/gray_scott/color.rb

Constant Summary

Constants included from XumoShortHand

XumoShortHand::SFloat, XumoShortHand::UInt8

Instance Method Summary collapse

Instance Method Details

#blue(ar) ⇒ Object



66
67
68
# File 'lib/gray_scott/color.rb', line 66

def blue(ar)
  uint8_zeros_256(2, ar)
end

#colorize(ar, color_type) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gray_scott/color.rb', line 7

def colorize(ar, color_type)
  case color_type
  when 'colorful'
    hsv2rgb(ar)
  when 'reverse-colorful'
    hsv2rgb(1.0 - ar)
  when 'red'
    red(ar)
  when 'green'
    green(ar)
  when 'blue'
    blue(ar)
  when 'reverse-red'
    reverse_red(ar)
  when 'reverse-green'
    reverse_green(ar)
  when 'reverse-blue'
    reverse_blue(ar)
  when 'grayscale'
    grayscale(ar)
  end
end

#grayscale(ar) ⇒ Object



82
83
84
85
# File 'lib/gray_scott/color.rb', line 82

def grayscale(ar)
  d = ar * 255
  uInt8_dstack([d, d, d])
end

#green(ar) ⇒ Object



62
63
64
# File 'lib/gray_scott/color.rb', line 62

def green(ar)
  uint8_zeros_256(1, ar)
end

#hsv2rgb(h) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/gray_scott/color.rb', line 39

def hsv2rgb(h)
  i = UInt8.cast(h * 6)
  f = (h * 6.0) - i
  p = UInt8.zeros *h.shape
  v = UInt8.new(*h.shape).fill 255
  q = (1.0 - f) * 256
  t = f * 256
  rgb = UInt8.zeros *h.shape, 3
  t = UInt8.cast(t)
  i = uInt8_dstack([i, i, i])
  rgb[i.eq 0] = uInt8_dstack([v, t, p])[i.eq 0]
  rgb[i.eq 1] = uInt8_dstack([q, v, p])[i.eq 1]
  rgb[i.eq 2] = uInt8_dstack([p, v, t])[i.eq 2]
  rgb[i.eq 3] = uInt8_dstack([p, q, v])[i.eq 3]
  rgb[i.eq 4] = uInt8_dstack([t, p, v])[i.eq 4]
  rgb[i.eq 5] = uInt8_dstack([v, p, q])[i.eq 5]
  rgb
end

#red(ar) ⇒ Object



58
59
60
# File 'lib/gray_scott/color.rb', line 58

def red(ar)
  uint8_zeros_256(0, ar)
end

#reverse_blue(ar) ⇒ Object



78
79
80
# File 'lib/gray_scott/color.rb', line 78

def reverse_blue(ar)
  uint8_zeros_256(2, (1.0 - ar))
end

#reverse_green(ar) ⇒ Object



74
75
76
# File 'lib/gray_scott/color.rb', line 74

def reverse_green(ar)
  uint8_zeros_256(1, (1.0 - ar))
end

#reverse_red(ar) ⇒ Object



70
71
72
# File 'lib/gray_scott/color.rb', line 70

def reverse_red(ar)
  uint8_zeros_256(0, (1.0 - ar))
end

#uInt8_dstack(ar) ⇒ Object

speed



31
32
33
34
35
36
37
# File 'lib/gray_scott/color.rb', line 31

def uInt8_dstack(ar)
  x = UInt8.zeros(*ar[0].shape, 3)
  x[true, true, 0] = ar[0]
  x[true, true, 1] = ar[1]
  x[true, true, 2] = ar[2]
  x
end