Class: Ombre
- Inherits:
-
Object
- Object
- Ombre
- Defined in:
- lib/ombre.rb
Class Method Summary collapse
- .diagonal(color1, color2, text, dir = "down") ⇒ Object
- .horizontal(color1, color2, text) ⇒ Object
- .vertical(color1, color2, text) ⇒ Object
Class Method Details
.diagonal(color1, color2, text, dir = "down") ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ombre.rb', line 18 def self.diagonal color1, color2, text, dir="down" 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 = dir=="down" ? (y + x)/(max_y + max_x).to_f : (max_y - y + x)/(max_y + max_x).to_f red, green, blue = get_offset_color color1, color2, ratio color_text red, green, blue, char end.join end.join end |
.horizontal(color1, color2, text) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/ombre.rb', line 9 def self.horizontal color1, color2, text text.lines.map do |line| line.chars.each_with_index.map do |char, i| red, green, blue = get_offset_color color1, color2, i/text.lines.max.length.to_f color_text red, green, blue, char end.join end.join end |
.vertical(color1, color2, text) ⇒ Object
2 3 4 5 6 7 |
# File 'lib/ombre.rb', line 2 def self.vertical color1, color2, text text.lines.each_with_index.map do |line, i| red, green, blue = get_offset_color color1, color2, i/text.lines.count.to_f color_text red, green, blue, line end.join end |