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 +4 -4
- data/lib/rainbow_colors/image_palette.rb +2 -23
- data/lib/rainbow_colors/palette.rb +31 -0
- data/lib/rainbow_colors/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4d8d8f6c2899b9819b869f51828dcae8ff06abe
|
4
|
+
data.tar.gz: 4a812669dccf064e01196fd0a71ab9dd2c6aaac2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
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.
|
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-
|
12
|
+
date: 2016-03-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rmagick
|