rainbow_colors 0.3.6 → 0.4.0
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/palette.rb +24 -22
- data/lib/rainbow_colors/scheme.rb +33 -30
- 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: f7d0e327e09c87a2b3b1c8395b11520d07e01142
|
4
|
+
data.tar.gz: aac4ec4a7b55a748931748d7b1eb2cc8acd6054e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4387e08c872c592a4baa70b186269db36fc2455192008cd1c60fc9c45b8e4aafe0a560aa153a42f606c1378dcfaf884f911a18a61bb8bf72658c7904d4497d17
|
7
|
+
data.tar.gz: 3c8f0849183b27e1b0d0057109b9c18a9255599930c65beb53df1bb39ab7961aabcdba09b2d731dece147f5398b6b852a62f03e80336c16057ad3bf232462003
|
@@ -1,23 +1,25 @@
|
|
1
1
|
module RainbowColors
|
2
2
|
class Palette
|
3
|
-
def self.
|
4
|
-
|
5
|
-
green = rand(255)
|
6
|
-
blue = rand(255)
|
3
|
+
def self.palette(base_color, scheme = :complementary)
|
4
|
+
grays = RainbowColors::Scheme.harmonious_grays(base_color)
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
6
|
+
palette = case scheme
|
7
|
+
when :analogous
|
8
|
+
RainbowColors::Scheme.analogous(base_color)
|
9
|
+
when :complementary
|
10
|
+
RainbowColors::Scheme.complementary(base_color)
|
11
|
+
when :complementary_split
|
12
|
+
RainbowColors::Scheme.complementary_split(base_color)
|
13
|
+
when :triad
|
14
|
+
RainbowColors::Scheme.triad(base_color)
|
15
|
+
when :shades
|
16
|
+
RainbowColors::Scheme.shades(base_color)
|
17
|
+
when :tints
|
18
|
+
RainbowColors::Scheme.tints(base_color)
|
19
|
+
end
|
20
|
+
palette.shift # Remove base color
|
21
|
+
|
22
|
+
[base_color, grays.first, grays.last, palette.sample]
|
21
23
|
end
|
22
24
|
|
23
25
|
def self.color_text(color_background)
|
@@ -33,15 +35,15 @@ module RainbowColors
|
|
33
35
|
background_brightness < 145 ? "#E6E6E6" : "#1A1A1A"
|
34
36
|
end
|
35
37
|
|
36
|
-
def self.color_accent(
|
38
|
+
def self.color_accent(color_palette, color_background)
|
37
39
|
bg = RainbowColors::Convertor.rgb_from_hex color_background
|
38
|
-
|
40
|
+
color_palette = color_scheme.map { |hex| RainbowColors::Convertor.rgb_from_hex(hex) }
|
39
41
|
|
40
42
|
contrast_colors = []
|
41
|
-
|
42
|
-
delta_red = [bg[:red],
|
43
|
+
color_palette.each do |c|
|
44
|
+
delta_red = [bg[:red], c[:red]].max - [bg[:red], c[:red]].min
|
43
45
|
delta_green = [bg[:green], c[:green]].max - [bg[:green], c[:green]].min
|
44
|
-
delta_blue = [bg[:blue],
|
46
|
+
delta_blue = [bg[:blue], c[:blue]].max - [bg[:blue], c[:blue]].min
|
45
47
|
color_difference = delta_red + delta_green + delta_blue
|
46
48
|
|
47
49
|
contrast_colors << RainbowColors::Convertor.hex_from_rgb(c) if color_difference > 250
|
@@ -1,58 +1,61 @@
|
|
1
1
|
module RainbowColors
|
2
2
|
class Scheme
|
3
|
-
def
|
4
|
-
|
3
|
+
def self.analogous(base_color)
|
4
|
+
secondary = color_with_variance 30, base_color
|
5
|
+
tertiary = color_with_variance -30, base_color
|
6
|
+
|
7
|
+
[base_color, secondary, tertiary]
|
5
8
|
end
|
6
9
|
|
7
|
-
def
|
8
|
-
secondary = color_with_variance
|
9
|
-
tertiary = color_with_variance -30
|
10
|
+
def self.complementary(base_color)
|
11
|
+
secondary = color_with_variance 180, base_color
|
10
12
|
|
11
|
-
[
|
13
|
+
[base_color, secondary]
|
12
14
|
end
|
13
15
|
|
14
|
-
def
|
15
|
-
secondary = color_with_variance
|
16
|
+
def self.complementary_split(base_color)
|
17
|
+
secondary = color_with_variance 150, base_color
|
18
|
+
tertiary = color_with_variance 210, base_color
|
16
19
|
|
17
|
-
[
|
20
|
+
[base_color, secondary, tertiary]
|
18
21
|
end
|
19
22
|
|
20
|
-
def
|
21
|
-
secondary = color_with_variance
|
22
|
-
tertiary = color_with_variance
|
23
|
+
def self.triad(base_color)
|
24
|
+
secondary = color_with_variance 120, base_color
|
25
|
+
tertiary = color_with_variance -120, base_color
|
23
26
|
|
24
|
-
[
|
27
|
+
[base_color, secondary, tertiary]
|
25
28
|
end
|
26
29
|
|
27
|
-
def
|
28
|
-
|
29
|
-
tertiary = color_with_variance -120
|
30
|
-
|
31
|
-
[@primary_color, secondary, tertiary]
|
30
|
+
def self.tints(base_color)
|
31
|
+
shades_tints "#FFFFFF", base_color
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
35
|
-
shades_tints "#
|
34
|
+
def self.shades(base_color)
|
35
|
+
shades_tints "#000000", base_color
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
39
|
-
|
38
|
+
def self.harmonious_grays(base_color)
|
39
|
+
weight = 90
|
40
|
+
colors = []
|
41
|
+
colors << mix("#424242", base_color, weight)
|
42
|
+
colors << mix("#FAFAFA", base_color, weight)
|
43
|
+
colors
|
40
44
|
end
|
41
45
|
|
42
46
|
private
|
43
47
|
|
44
|
-
def color_with_variance(variance)
|
45
|
-
rgb = RainbowColors::Convertor.rgb_from_hex
|
48
|
+
private_class_method def self.color_with_variance(variance, base_color)
|
49
|
+
rgb = RainbowColors::Convertor.rgb_from_hex base_color
|
46
50
|
hsl = RainbowColors::Convertor.hsl_from_rgb rgb
|
47
51
|
|
48
52
|
color = RainbowColors::Convertor.rgb_from_hsl({ hue: hsl[:hue] + variance, saturation: hsl[:saturation], luminance: hsl[:luminance] })
|
49
|
-
|
50
53
|
RainbowColors::Convertor.hex_from_rgb color
|
51
54
|
end
|
52
55
|
|
53
56
|
# Algorithm shamelessly stolen from SASS:
|
54
57
|
# https://github.com/sass/sass/blob/stable/lib/sass/script/functions.rb#L1313
|
55
|
-
def mix(color1, color2, weight)
|
58
|
+
private_class_method def self.mix(color1, color2, weight)
|
56
59
|
color1 = RainbowColors::Convertor.rgb_from_hex color1
|
57
60
|
color2 = RainbowColors::Convertor.rgb_from_hex color2
|
58
61
|
|
@@ -69,15 +72,15 @@ module RainbowColors
|
|
69
72
|
RainbowColors::Convertor.hex_from_rgb({ red: r, green: g, blue: b })
|
70
73
|
end
|
71
74
|
|
72
|
-
def shades_tints(mix_color)
|
73
|
-
colors = [
|
75
|
+
private_class_method def self.shades_tints(mix_color, base_color)
|
76
|
+
colors = [base_color]
|
74
77
|
|
75
|
-
weight =
|
78
|
+
weight = 0
|
76
79
|
increment = 15
|
77
80
|
|
78
81
|
5.times do
|
79
82
|
weight = weight + increment
|
80
|
-
colors.push mix(mix_color,
|
83
|
+
colors.push mix(mix_color, base_color, weight)
|
81
84
|
end
|
82
85
|
|
83
86
|
colors
|
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.
|
4
|
+
version: 0.4.0
|
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-04-
|
12
|
+
date: 2016-04-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rmagick
|