ombre 0.0.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -16
  3. data/lib/ombre.rb +39 -13
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99ef7e0c740ae6704b914f1a85ae7d9a05689ad732f8105c60daeb1d143a499f
4
- data.tar.gz: 4580fe57eda1715b5b8ac69e1479cbd694560fb90f997300da334d29d15b7810
3
+ metadata.gz: 0d8a4ddbfcbaa0f408f2bfc24ef443a72c8c66dd4167e2be8d68981ac8b29838
4
+ data.tar.gz: b69094d4367a287bf35a058b8c9b32f8b4af026a92a49045fb5cdc3a87e820b7
5
5
  SHA512:
6
- metadata.gz: a1030837e5379c62320c9546297e957ed09fb85f8c0b81baec2db5dd814651bdf3f9164136d35591fa56eac691363a4da3b83822af1286515684b632ad23fa0c
7
- data.tar.gz: e913df099cd9d9114d604c95e0d3236dd914b8ec5a70c52834f4fe7f9f133ad095d9e4a3abdf846f3a1c12d53370323e4eef08e2a6ff8ba5865afa3f43f19566
6
+ metadata.gz: 30326d68bfea689327dbb6852fb4cd46fd1cbe84a1fb5e422b58771eb402fccb5c7206116a05c5e6866883be4560bb3249c9e2b167c6613f0273d67cdad86b0d
7
+ data.tar.gz: 1084d2fecaca0e70de079434a92a54e68f52aa3068e2ab8999c9909f0784bd10113ecc0a0ed431643e8c60a8d5ff652597ce6ad8b96dec258fbbe8d508697f53
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # Ruby Ombre
2
2
 
3
- Ombre provides gradients for your terminal between any two hexidecimal RGB values.
3
+ Ombre provides gradients for your terminal between any number of RGB values.
4
4
 
5
5
  ## Features
6
6
 
7
- * Horizontal, vertical, and diagonal (both directions) gradients from one color to another.
7
+ * Horizontal, vertical, and diagonal gradients for any number of colors.
8
8
  ## True Color Support
9
9
 
10
- This will only look gook on terminals that support 24bit colors, for now.
10
+ This will only look good on terminals that support 24bit colors, for now.
11
11
 
12
12
  ## Setup
13
13
 
@@ -27,25 +27,26 @@ require 'ombre'
27
27
 
28
28
  ## Usage
29
29
 
30
- There are three main functions available for `Ombre`:
30
+ There are four main functions available for `Ombre`:
31
31
 
32
32
  ```ruby
33
- # from_color and to_color in the below functions should be 24 bit hexidecimal RGB values as strings.
33
+ # colors in the below functions should be an array of 24 bit hexidecimal RGB values as strings.
34
34
 
35
35
  # Returns the block of text marked up with colors to create a horizontal gradient from left to right
36
- Ombre.horizontal(from_color, to_color, text)
37
- Ombre.horizontal("FF0000", "0000FF", "############\n# #\n# Horiz. ###\n# Ombre ####\n# Test #####\n# From #####\n# Red ######\n# To #######\n# Blue #####\n# #\n############")
36
+ Ombre.horizontal(text, colors)
37
+ Ombre.horizontal("############\n# #\n# Horiz. ###\n# Ombre ####\n# Test #####\n# From #####\n# Red ######\n# To #######\n# Blue #####\n# #\n############", ["FF0000", "0000FF"])
38
38
 
39
39
  # Returns the block of text marked up with colors to create a vertical gradient from top to bottom
40
- Ombre.vertical(from_color, to_color, text)
41
- Ombre.vertical("FF0000", "0000FF", "############\n# #\n# Vertical #\n# Ombre ####\n# Test #####\n# From #####\n# Red ######\n# To #######\n# Blue #####\n# #\n############")
42
-
43
- # Returns the block of text marked up with colors to create a diagonal gradient
44
- Ombre.diagonal(from_color, to_color, text)
45
- # from top-left to bottom-right by default
46
- Ombre.diagonal("FF0000", "0000FF", "############\n# #\n# Diagonal #\n# Ombre ####\n# Test #####\n# From #####\n# Red ######\n# To #######\n# Blue #####\n# #\n############")
47
- # from bottom-left to top-right changing the last argument
48
- Ombre.diagonal("FF0000", "0000FF", "############\n# #\n# Diagonal #\n# Ombre ####\n# Test #####\n# From #####\n# Red ######\n# To #######\n# Blue #####\n# #\n############", "up")
40
+ Ombre.vertical(text, colors)
41
+ Ombre.vertical("############\n# #\n# Vertical #\n# Ombre ####\n# Test #####\n# From #####\n# Red ######\n# To #######\n# Blue #####\n# #\n############", ["FF0000", "0000FF"])
42
+
43
+ # Returns the block of text marked up with colors to create a diagonal gradient from top-left to bottom-right
44
+ Ombre.diagonal(text, colors)
45
+ Ombre.diagonal("############\n# #\n# Diagonal #\n# Ombre ####\n# Test #####\n# From #####\n# Red ######\n# To #######\n# Blue #####\n# #\n############", ["FF0000", "0000FF"])
46
+
47
+ # Returns the block of text marked up with colors to create a diagonal gradient from bottom-left to top-right
48
+ Ombre.diagonal_up(text, colors)
49
+ Ombre.diagonal_up("############\n# #\n# Diagonal #\n# Ombre ####\n# Test #####\n# From #####\n# Red ######\n# To #######\n# Blue #####\n# #\n############", ["FF0000", "0000FF"])
49
50
  ```
50
51
 
51
52
 
data/lib/ombre.rb CHANGED
@@ -1,51 +1,77 @@
1
1
  class Ombre
2
- def self.vertical color1, color2, text
2
+ def self.vertical text, colors
3
3
  text.lines.each_with_index.map do |line, i|
4
- red, green, blue = get_offset_color color1, color2, i/text.lines.count.to_f
4
+ red, green, blue = get_offset_color colors, i/text.lines.count.to_f
5
5
  color_text red, green, blue, line
6
6
  end.join
7
7
  end
8
8
 
9
- def self.horizontal color1, color2, text
9
+ def self.horizontal text, colors
10
10
  text.lines.map do |line|
11
11
  line.chars.each_with_index.map do |char, i|
12
- red, green, blue = get_offset_color color1, color2, i/text.lines.max.length.to_f
12
+ red, green, blue = get_offset_color colors, i/text.lines.max.length.to_f
13
13
  color_text red, green, blue, char
14
14
  end.join
15
15
  end.join
16
16
  end
17
17
 
18
- def self.diagonal color1, color2, text, dir="down"
18
+ def self.diagonal text, colors
19
19
  max_y = text.lines.count
20
20
  max_x = text.lines.max.length
21
21
  text.lines.each_with_index.map do |line, y|
22
22
  line.chars.each_with_index.map do |char, x|
23
- ratio = dir=="down" ? (y + x)/(max_y + max_x).to_f : (max_y - y + x)/(max_y + max_x).to_f
24
- red, green, blue = get_offset_color color1, color2, ratio
23
+ ratio = (y + x)/(max_y + max_x).to_f
24
+ red, green, blue = get_offset_color colors, ratio
25
25
  color_text red, green, blue, char
26
26
  end.join
27
27
  end.join
28
28
  end
29
29
 
30
+ def self.diagonal_up text, colors
31
+ max_y = text.lines.count
32
+ max_x = text.lines.max.length
33
+ text.lines.each_with_index.map do |line, y|
34
+ line.chars.each_with_index.map do |char, x|
35
+ ratio = (max_y - y + x)/(max_y + max_x).to_f
36
+ red, green, blue = get_offset_color colors, ratio
37
+ color_text red, green, blue, char
38
+ end.join
39
+ end.join
40
+ end
41
+
30
42
  private
31
43
 
32
44
  def self.get_colors color
33
45
  color = color.gsub('#','')
46
+
34
47
  red = color[0..1].to_i(16).to_f
35
48
  green = color[2..3].to_i(16).to_f
36
49
  blue = color[4..5].to_i(16).to_f
50
+
37
51
  [red, green, blue]
38
52
  end
39
53
 
40
- def self.get_offset_color c1, c2, ratio
41
- r1, g1, b1 = get_colors c1
42
- r2, g2, b2 = get_colors c2
43
- r_dist = (r1-r2).abs * ratio
54
+ def self.get_offset_color colors, ratio
55
+ segment = -1
56
+ segment += 1 while ratio > (segment + 1)/(colors.count - 1).to_f && segment < colors.count - 2
57
+
58
+ color1 = colors[segment]
59
+ color2 = colors[segment+1]
60
+
61
+ percent = (ratio - segment/(colors.count-1).to_f)/(1/(colors.count-1).to_f)
62
+
63
+ r1, g1, b1 = get_colors color1
64
+ r2, g2, b2 = get_colors color2
65
+
66
+ r_dist = (r1-r2).abs * percent
44
67
  red = r1 > r2 ? r1 - r_dist : r1 + r_dist
45
- g_dist = (g1-g2).abs * ratio
68
+
69
+ g_dist = (g1-g2).abs * percent
46
70
  green = g1 > g2 ? g1 - g_dist : g1 + g_dist
47
- b_dist = (b1-b2).abs * ratio
71
+
72
+ b_dist = (b1-b2).abs * percent
48
73
  blue = b1 > b2 ? b1 - b_dist : b1 + b_dist
74
+
49
75
  [red, green, blue]
50
76
  end
51
77
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ombre
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Paulson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-20 00:00:00.000000000 Z
11
+ date: 2022-04-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Provides gradient colors for command line output using RGB hex values.
14
14
  email: jpaulson@hey.com