ombre 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +53 -0
  3. data/lib/ombre.rb +25 -11
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd24e51a4a0474d903fd3b012848fdcaa3cec7e5e07d5b35cddce11a7b190d1d
4
- data.tar.gz: 6abacfc82cfd70b3c7117e0b6ff521aa2d167ebb184826e12fe6fac1c7df18d7
3
+ metadata.gz: 3eff2b1fed47b5f5b2b632e86d71d74378f7dcaa46e2f64f2a7bb8c6120d014a
4
+ data.tar.gz: 1eeb141aec14ed6eaa30ed2da91c9b05bd5008cc8ece93e5bf84d0353cb9e0b3
5
5
  SHA512:
6
- metadata.gz: d363322c1244e03111d7e941a7b51281e41b0e9e5e0ed1a54156ea9435dcdbac19213878da9b13da117b92378d6752e7bcd7218e580ff28d70a3804fc0c9202f
7
- data.tar.gz: 8896b50a283742f8fd34ebfb522dce8ee2eabecb4bdbf09a6690bb4eef69f8df388d6a4d8a70f55183889458ca0b28c6bf4ba2a5c736979105ad6567f5c83623
6
+ metadata.gz: 81bc7424ea8bf8f59607207d466916042cb8e538f2b0274a48a4e30b2b3f241ae2b939e31bbeee118bc2e719ca6e18453f03cdc2e5ee9f7700d2334ea36c21c2
7
+ data.tar.gz: 1619d5c36cbc90ff613cb44536204859f496e7dda6ad8197d581d34a984ceacb7fca465902d61e133ca2db515bd129a3c89d0465058332f5f2e56a83c2b0ceb6
data/README.md CHANGED
@@ -0,0 +1,53 @@
1
+ # Ruby Ombre
2
+
3
+ Ombre provides gradients for your terminal between any two hexidecimal RGB values.
4
+
5
+ ## Features
6
+
7
+ * Horizontal, vertical, and diagonal (both directions) gradients from one color to another.
8
+ ## True Color Support
9
+
10
+ This will only look gook on terminals that support 24bit colors, for now.
11
+
12
+ ## Setup
13
+
14
+ Add to `Gemfile`:
15
+
16
+ ```ruby
17
+ gem 'ombre'
18
+ ```
19
+
20
+ and run `bundle install`.
21
+
22
+ In Ruby do:
23
+
24
+ ```ruby
25
+ require 'ombre'
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ There are three main functions available for `Ombre`:
31
+
32
+ ```ruby
33
+ # from_color and to_color in the below functions should be 24 bit hexidecimal RGB values as strings.
34
+
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############")
38
+
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")
49
+ ```
50
+
51
+
52
+ Copyright (c) 2022 Justin Paulson, released under the
53
+ MIT license.
data/lib/ombre.rb CHANGED
@@ -1,20 +1,28 @@
1
1
  class Ombre
2
2
  def self.vertical color1, color2, text
3
- red1, green1, blue1 = get_colors(color1)
4
- red2, green2, blue2 = get_colors(color2)
5
- r_step, g_step, b_step = get_steps(color1, color2, text.lines.count)
6
3
  text.lines.each_with_index.map do |line, i|
7
- color_text (red1 + i * r_step), (green1 + i * g_step), (blue1 + i * b_step), line
4
+ red, green, blue = get_offset_color color1, color2, i/text.lines.count.to_f
5
+ color_text red, green, blue, line
8
6
  end.join
9
7
  end
10
8
 
11
9
  def self.horizontal color1, color2, text
12
- red1, green1, blue1 = get_colors(color1)
13
- red2, green2, blue2 = get_colors(color2)
14
- r_step, g_step, b_step = get_steps(color1, color2, text.lines.max.length)
15
10
  text.lines.map do |line|
16
- line.chars.each_with_index.map do |line, i|
17
- color_text (red1 + i * r_step), (green1 + i * g_step), (blue1 + i * b_step), line
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
13
+ color_text red, green, blue, char
14
+ end.join
15
+ end.join
16
+ end
17
+
18
+ def self.diagonal color1, color2, text, dir="down"
19
+ max_y = text.lines.count
20
+ max_x = text.lines.max.length
21
+ text.lines.each_with_index.map do |line, y|
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
25
+ color_text red, green, blue, char
18
26
  end.join
19
27
  end.join
20
28
  end
@@ -29,10 +37,16 @@ class Ombre
29
37
  [red, green, blue]
30
38
  end
31
39
 
32
- def self.get_steps c1, c2, i
40
+ def self.get_offset_color c1, c2, ratio
33
41
  r1, g1, b1 = get_colors c1
34
42
  r2, g2, b2 = get_colors c2
35
- [(r2-r1)/i.to_f, (g2-g1)/i.to_f, (b2-b1)/i.to_f]
43
+ r_dist = (r1-r2).abs * ratio
44
+ red = r1 > r2 ? r1 - r_dist : r1 + r_dist
45
+ g_dist = (g1-g2).abs * ratio
46
+ green = g1 > g2 ? g1 - g_dist : g1 + g_dist
47
+ b_dist = (b1-b2).abs * ratio
48
+ blue = b1 > b2 ? b1 - b_dist : b1 + b_dist
49
+ [red, green, blue]
36
50
  end
37
51
 
38
52
  def self.color_text r, g, b, text
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ombre
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Paulson