rainbow_colors 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97eb58ce4b49c9cc24e4388c64c5384dbaba54c9
4
- data.tar.gz: 2c4962729f215682f31535a6585216c23dd269cb
3
+ metadata.gz: f4d8d8f6c2899b9819b869f51828dcae8ff06abe
4
+ data.tar.gz: 4a812669dccf064e01196fd0a71ab9dd2c6aaac2
5
5
  SHA512:
6
- metadata.gz: 56d926650b9d6b5b7cb1316c175d6c627d095c1494ce563edd9653d1831b547efdb725c8ad907cf4d449c1836716c5d29c330c9a382a7ec445b1e5d7abd443bd
7
- data.tar.gz: 1a0a77df341214e6bec280f11f9a753a4cd08140973a8e479bcd8528c0e9e5159cfe204f0b5535f784756c5cb96e1c8164b8864f7be1e4f9e0bb0b6e6c862209
6
+ metadata.gz: 2ecba92f753ffa332e9290ec3bf9f1ae07c7fe5b72f8fff9b3ec686bf6b09697c594de22f4b6efc5a407dc8b3850a7b960186697f5bbcc8a8dec8906562c227f
7
+ data.tar.gz: 753cc81cf2dec369c3643ab975770979456775533daacf6e03239608fa9fd289fdc7acd38bd9341ca50638efbec58fc4025e3a1420a68b89fc3f89fc2293beba
@@ -50,32 +50,11 @@ module RainbowColors
50
50
  end
51
51
 
52
52
  def color_text
53
- background_rgb = RainbowColors::Convertor.rgb_from_hex color_background
54
- # http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx
55
- background_brightness = Math.sqrt(
56
- background_rgb[:red] ** 2 * 0.241 +
57
- background_rgb[:green] ** 2 * 0.691 +
58
- background_rgb[:blue] ** 2 * 0.068
59
- )
60
- background_brightness < 145 ? "#E6E6E6" : "#1A1A1A"
53
+ RainbowColors::Palette.color_text color_background
61
54
  end
62
55
 
63
56
  def color_accent
64
- bg = RainbowColors::Convertor.rgb_from_hex color_background
65
- color_scheme = scheme.map { |hex| RainbowColors::Convertor.rgb_from_hex(hex) }
66
-
67
- contrast_colors = []
68
- color_scheme.each do |c|
69
- delta_red = [bg[:red], c[:red]].max - [bg[:red], c[:red]].min
70
- delta_green = [bg[:green], c[:green]].max - [bg[:green], c[:green]].min
71
- delta_blue = [bg[:blue], c[:blue]].max - [bg[:blue], c[:blue]].min
72
- color_difference = delta_red + delta_green + delta_blue
73
-
74
- contrast_colors << RainbowColors::Convertor.hex_from_rgb(c) if color_difference > 225
75
- end
76
-
77
- # Return random contrasting color color, if available
78
- contrast_colors.empty? ? color_text : contrast_colors.sample
57
+ RainbowColors::Palette.color_accent scheme, color_background
79
58
  end
80
59
 
81
60
  private
@@ -19,5 +19,36 @@ module RainbowColors
19
19
  RainbowColors::Convertor.hex_from_hsl hsl
20
20
  end
21
21
  end
22
+
23
+ def self.color_text(color_background)
24
+ background_rgb = RainbowColors::Convertor.rgb_from_hex color_background
25
+
26
+ # http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx
27
+ background_brightness = Math.sqrt(
28
+ background_rgb[:red] ** 2 * 0.241 +
29
+ background_rgb[:green] ** 2 * 0.691 +
30
+ background_rgb[:blue] ** 2 * 0.068
31
+ )
32
+
33
+ background_brightness < 145 ? "#E6E6E6" : "#1A1A1A"
34
+ end
35
+
36
+ def self.color_accent(color_scheme, color_background)
37
+ bg = RainbowColors::Convertor.rgb_from_hex color_background
38
+ color_scheme.map! { |hex| RainbowColors::Convertor.rgb_from_hex(hex) }
39
+
40
+ contrast_colors = []
41
+ color_scheme.each do |c|
42
+ delta_red = [bg[:red], c[:red]].max - [bg[:red], c[:red]].min
43
+ delta_green = [bg[:green], c[:green]].max - [bg[:green], c[:green]].min
44
+ delta_blue = [bg[:blue], c[:blue]].max - [bg[:blue], c[:blue]].min
45
+ color_difference = delta_red + delta_green + delta_blue
46
+
47
+ contrast_colors << RainbowColors::Convertor.hex_from_rgb(c) if color_difference > 225
48
+ end
49
+
50
+ # Return random contrasting color color, if available
51
+ contrast_colors.empty? ? self.color_text(color_background) : contrast_colors.sample
52
+ end
22
53
  end
23
54
  end
@@ -1,3 +1,3 @@
1
1
  module RainbowColors
2
- VERSION = "0.3.1".freeze
2
+ VERSION = "0.3.2".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rainbow_colors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ashish Kumar
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-03-02 00:00:00.000000000 Z
12
+ date: 2016-03-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rmagick