ombre 0.0.0 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE.txt +0 -0
  3. data/README.md +53 -0
  4. data/lib/ombre.rb +26 -12
  5. metadata +9 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbf20e9c3c9c4424d3ae4f3675ec90e2532b07d5f127b2dd52ca03dfad89fd82
4
- data.tar.gz: 8ec60035f8581e0b5b3b9e70029730db208732b536b0d132f58d0974cada9b6e
3
+ metadata.gz: 99ef7e0c740ae6704b914f1a85ae7d9a05689ad732f8105c60daeb1d143a499f
4
+ data.tar.gz: 4580fe57eda1715b5b8ac69e1479cbd694560fb90f997300da334d29d15b7810
5
5
  SHA512:
6
- metadata.gz: 56050a7bec0ec9a6af03c8fda56a53220cc630b79a0b31a4a88082e5a74ad920841a754f6c0308b6fe418ed0b122b85b812dd2bce8ec75d5fd3085bf54c16848
7
- data.tar.gz: e7fac2bd9ca52d54ead214917ffedd620b92a1f50ae582ca328e9a0344cc3ed77f1f5ff60ad01c4842e71277ac3590fa88007f25aa426fc92ad68c2cb0c98429
6
+ metadata.gz: a1030837e5379c62320c9546297e957ed09fb85f8c0b81baec2db5dd814651bdf3f9164136d35591fa56eac691363a4da3b83822af1286515684b632ad23fa0c
7
+ data.tar.gz: e913df099cd9d9114d604c95e0d3236dd914b8ec5a70c52834f4fe7f9f133ad095d9e4a3abdf846f3a1c12d53370323e4eef08e2a6ff8ba5865afa3f43f19566
data/MIT-LICENSE.txt ADDED
File without changes
data/README.md ADDED
@@ -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,13 +37,19 @@ 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
39
- "\x1b[38;2;#{r.to_i};#{g.to_i};#{b.to_i}m#{text}"
53
+ "\x1b[38;2;#{r.to_i};#{g.to_i};#{b.to_i}m#{text}\x1b[0m"
40
54
  end
41
55
  end
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.0
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Paulson
@@ -10,14 +10,18 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2022-04-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Provides gradient colors for the command line using truecolor
13
+ description: Provides gradient colors for command line output using RGB hex values.
14
14
  email: jpaulson@hey.com
15
15
  executables: []
16
16
  extensions: []
17
- extra_rdoc_files: []
17
+ extra_rdoc_files:
18
+ - README.md
19
+ - MIT-LICENSE.txt
18
20
  files:
21
+ - MIT-LICENSE.txt
22
+ - README.md
19
23
  - lib/ombre.rb
20
- homepage: https://rubygems.org/gems/ombre
24
+ homepage: https://github.com/justinpaulson/ombre
21
25
  licenses:
22
26
  - MIT
23
27
  metadata: {}
@@ -39,5 +43,5 @@ requirements: []
39
43
  rubygems_version: 3.1.2
40
44
  signing_key:
41
45
  specification_version: 4
42
- summary: Ombre
46
+ summary: Ombre gradients for your terminal!
43
47
  test_files: []