rainbow_colors 0.3.6 → 0.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b04fcca94f5cbc2a844fb6369243f505b7e20408
4
- data.tar.gz: a132bce814daf7dd0936927233440b3d39582ea3
3
+ metadata.gz: f7d0e327e09c87a2b3b1c8395b11520d07e01142
4
+ data.tar.gz: aac4ec4a7b55a748931748d7b1eb2cc8acd6054e
5
5
  SHA512:
6
- metadata.gz: 17bca7fc2396c91a7df4613abb23ebce212ddc1542aff8e6e4608f9316c60e260f95f6feb0cfdb09797e3507dbabbdae0506d85c12db00f6afb0d6d752f3949f
7
- data.tar.gz: f6ff2ad58f6a173a0a350d13b3a095ad3c084003996f3959d2ff222e11ec8628add443eb81668f97ac90e3d65f9a5e8bbbe539606866e0a0eb82eb378a283468
6
+ metadata.gz: 4387e08c872c592a4baa70b186269db36fc2455192008cd1c60fc9c45b8e4aafe0a560aa153a42f606c1378dcfaf884f911a18a61bb8bf72658c7904d4497d17
7
+ data.tar.gz: 3c8f0849183b27e1b0d0057109b9c18a9255599930c65beb53df1bb39ab7961aabcdba09b2d731dece147f5398b6b852a62f03e80336c16057ad3bf232462003
@@ -1,23 +1,25 @@
1
1
  module RainbowColors
2
2
  class Palette
3
- def self.random_color
4
- red = rand(255)
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
- RainbowColors::Convertor.hex_from_rgb({ red: red, green: green, blue: blue })
9
- end
10
-
11
- def self.adjust_saturation(colors, variance)
12
- colors = colors.map do |c|
13
- hsl = RainbowColors::Convertor.hsl_from_hex c
14
- if variance > 0
15
- hsl[:saturation] = hsl[:saturation] + variance if hsl[:saturation] + variance <= 100
16
- else
17
- hsl[:saturation] = hsl[:saturation] + variance if hsl[:saturation] + variance >= 0
18
- end
19
- RainbowColors::Convertor.hex_from_hsl hsl
20
- end
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(color_scheme, color_background)
38
+ def self.color_accent(color_palette, color_background)
37
39
  bg = RainbowColors::Convertor.rgb_from_hex color_background
38
- color_scheme = color_scheme.map { |hex| RainbowColors::Convertor.rgb_from_hex(hex) }
40
+ color_palette = color_scheme.map { |hex| RainbowColors::Convertor.rgb_from_hex(hex) }
39
41
 
40
42
  contrast_colors = []
41
- color_scheme.each do |c|
42
- delta_red = [bg[:red], c[:red]].max - [bg[:red], c[:red]].min
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], c[:blue]].max - [bg[:blue], c[:blue]].min
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 initialize(primary_color_hex)
4
- @primary_color = primary_color_hex
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 analogous
8
- secondary = color_with_variance 30
9
- tertiary = color_with_variance -30
10
+ def self.complementary(base_color)
11
+ secondary = color_with_variance 180, base_color
10
12
 
11
- [@primary_color, secondary, tertiary]
13
+ [base_color, secondary]
12
14
  end
13
15
 
14
- def complementary
15
- secondary = color_with_variance 180
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
- [@primary_color, secondary]
20
+ [base_color, secondary, tertiary]
18
21
  end
19
22
 
20
- def complementary_split
21
- secondary = color_with_variance 150
22
- tertiary = color_with_variance 210
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
- [@primary_color, secondary, tertiary]
27
+ [base_color, secondary, tertiary]
25
28
  end
26
29
 
27
- def triad
28
- secondary = color_with_variance 120
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 tints
35
- shades_tints "#FAFAFA"
34
+ def self.shades(base_color)
35
+ shades_tints "#000000", base_color
36
36
  end
37
37
 
38
- def shades
39
- shades_tints "#424242"
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 @primary_color
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 = [@primary_color]
75
+ private_class_method def self.shades_tints(mix_color, base_color)
76
+ colors = [base_color]
74
77
 
75
- weight = 15
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, @primary_color, weight)
83
+ colors.push mix(mix_color, base_color, weight)
81
84
  end
82
85
 
83
86
  colors
@@ -1,3 +1,3 @@
1
1
  module RainbowColors
2
- VERSION = "0.3.6".freeze
2
+ VERSION = "0.4.0".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.6
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-18 00:00:00.000000000 Z
12
+ date: 2016-04-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rmagick