Class: Ombre

Inherits:
Object
  • Object
show all
Defined in:
lib/ombre.rb

Class Method Summary collapse

Class Method Details

.diagonal(text, colors) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ombre.rb', line 18

def self.diagonal text, colors
  max_y = text.lines.count
  max_x = text.lines.max.length
  text.lines.each_with_index.map do |line, y|
    line.chars.each_with_index.map do |char, x|
      ratio = (y + x)/(max_y + max_x).to_f
      red, green, blue = get_offset_color colors, ratio
      color_text red, green, blue, char
    end.join
  end.join
end

.diagonal_up(text, colors) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ombre.rb', line 30

def self.diagonal_up text, colors
  max_y = text.lines.count
  max_x = text.lines.max.length
  text.lines.each_with_index.map do |line, y|
    line.chars.each_with_index.map do |char, x|
      ratio = (max_y - y + x)/(max_y + max_x).to_f
      red, green, blue = get_offset_color colors, ratio
      color_text red, green, blue, char
    end.join
  end.join
end

.horizontal(text, colors) ⇒ Object



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

def self.horizontal text, colors
  text.lines.map do |line|
    line.chars.each_with_index.map do |char, i|
      red, green, blue = get_offset_color colors, i/text.lines.max.length.to_f
      color_text red, green, blue, char
    end.join
  end.join
end

.vertical(text, colors) ⇒ Object



2
3
4
5
6
7
# File 'lib/ombre.rb', line 2

def self.vertical text, colors
  text.lines.each_with_index.map do |line, i|
    red, green, blue = get_offset_color colors, i/text.lines.count.to_f
    color_text red, green, blue, line
  end.join
end