Complementary_Color 0.1.4 → 0.1.5

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
  SHA256:
3
- metadata.gz: 7fed5107b46b1492acb17a262c8837862bf793ca7e29a85c052590f4b17107b7
4
- data.tar.gz: 3a71bfe464686ac48ea6a172eba31c89126f9a2393f6f803f466017dfb9a3666
3
+ metadata.gz: 31fc734fd0d69856e69bf70761225878595b441d53ca0553d9fff8143ca1b018
4
+ data.tar.gz: e9289443a4de434a4c00a46745b3564f237d89f13f39c715fea591d2782efc65
5
5
  SHA512:
6
- metadata.gz: 7a96b2ac021371abd1a2ffb33424d75eec3f12eb57f270a203d41d9948422ed9a4e3cfec42be4863ec262998ca31eecce3a93f627fec96435dad869892120f92
7
- data.tar.gz: ea7ce156cff60f6240a2507e81c9644c81f13130e9d73d1b196e42e984ac69eb8e4f8d2637ae960c9920b9f26e176da56dcf38913a92cb1156c45aa1b6c10d1d
6
+ metadata.gz: ad43f1a51ccda5e578a3f330ddbcb309ca801211181c7dc3b67171b39ec06dbd31d37dc0a82d65a59830f3acde0fc21ff38dcc8e36245051bee94cef7e73c425
7
+ data.tar.gz: f8d7b4096909ef0c53d632bfdd89893a64f5bdd6123c08deffa3e0499d8d1473ee9ea9b5c0252554bfbdda2e66f85991a903e0fedd9ec62ecfb9ef1297b1d14d
data/CHANGELOG.md CHANGED
@@ -1,56 +0,0 @@
1
- ## [0.1.1] - 2022-06-24
2
-
3
- - First functionality added
4
-
5
- ## [0.7.0](https://www.github.com/TimHi/Compelementary-Color/compare/v0.6.0...v0.7.0) (2022-06-25)
6
-
7
-
8
- ### Features
9
-
10
- * test ([90475db](https://www.github.com/TimHi/Compelementary-Color/commit/90475db7a6b65740e69d02004b058531aa86497c))
11
-
12
- ## [0.6.0](https://www.github.com/TimHi/Compelementary-Color/compare/v0.5.0...v0.6.0) (2022-06-25)
13
-
14
-
15
- ### Features
16
-
17
- * updating ci ([a50944c](https://www.github.com/TimHi/Compelementary-Color/commit/a50944c43d0dc3d3f996557b325a96ce17920aba))
18
-
19
- ## [0.5.0](https://www.github.com/TimHi/Compelementary-Color/compare/v0.4.0...v0.5.0) (2022-06-25)
20
-
21
-
22
- ### Features
23
-
24
- * dummy commit to test action ([bf86695](https://www.github.com/TimHi/Compelementary-Color/commit/bf8669576ce8bb18f423d5d840353cee657a1fdd))
25
-
26
- ## [0.4.0](https://www.github.com/TimHi/Compelementary-Color/compare/v0.3.0...v0.4.0) (2022-06-25)
27
-
28
-
29
- ### Features
30
-
31
- * test release ([eb004cd](https://www.github.com/TimHi/Compelementary-Color/commit/eb004cd523dbed9bf20d2b2d33eb0f4e1410771c))
32
-
33
- ## [0.3.0](https://www.github.com/TimHi/Compelementary-Color/compare/v0.2.0...v0.3.0) (2022-06-25)
34
-
35
-
36
- ### Features
37
-
38
- * dummy commit to test action ([4aa8117](https://www.github.com/TimHi/Compelementary-Color/commit/4aa81179154c56334191525e4dccb5ca054ea440))
39
-
40
- ## [0.2.0](https://www.github.com/TimHi/Compelementary-Color/compare/v0.1.0...v0.2.0) (2022-06-25)
41
-
42
-
43
- ### Features
44
-
45
- * adding new tests ([1c4807e](https://www.github.com/TimHi/Compelementary-Color/commit/1c4807e2a762d084bd0e089c0b09c31b2854b2b1))
46
-
47
- ## 0.1.0 (2022-06-25)
48
-
49
-
50
- ### Features
51
-
52
- * dummy commit to test action ([6779bd9](https://www.github.com/TimHi/Compelementary-Color/commit/6779bd92d9621a8ba1a63e1868ae4f9f82fab89a))
53
-
54
- ## [0.1.0] - 2022-06-21
55
-
56
- - Initial release
data/lib/color/hsv.rb ADDED
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Offering functionality related to the HSV color model.
4
+ module HSV
5
+ HUE_MULTIPLIER = 60
6
+ RGB_MAX_VALUE = 255
7
+ ROUND_VALUE = 3
8
+ FULL_CIRCLE_DEG = 360
9
+ MONO_SATURATION = 0.2
10
+ MONO_VALUE = 0.1
11
+
12
+ # Hex Colors can be represented with three characters, to work
13
+ def self.rgb_to_hsv(rgb_color)
14
+ max = rgb_color.max()
15
+ min = rgb_color.min()
16
+ r = rgb_color[0]
17
+ g = rgb_color[1]
18
+ b = rgb_color[2]
19
+
20
+ value = (max.to_f / RGB_MAX_VALUE).round(ROUND_VALUE)
21
+ max_min_diff = max - min
22
+ hue = calculate_hue(r, g, b, max_min_diff)
23
+ hue += FULL_CIRCLE_DEG if hue.negative?
24
+ [hue.round, calculate_saturation(max_min_diff, max, value), value]
25
+ end
26
+
27
+ def self.calculate_saturation(max_min_diff, max, value)
28
+ saturation = 0
29
+ saturation = (max_min_diff.to_f / max).round(ROUND_VALUE) if value.positive?
30
+ saturation
31
+ end
32
+
33
+ # Method to calculate the hue value of three given rgb colors and the difference
34
+ # of the max - min color.
35
+ def self.calculate_hue(red, green, blue, max_min_diff)
36
+ if red > green && red > blue
37
+ HUE_MULTIPLIER * calculate_raw_hue_value(0, green, blue, max_min_diff)
38
+ elsif green > red && green > blue
39
+ HUE_MULTIPLIER * calculate_raw_hue_value(2, blue, red, max_min_diff)
40
+ elsif blue > red && blue > green
41
+ HUE_MULTIPLIER * calculate_raw_hue_value(4, red, green, max_min_diff)
42
+ else
43
+ 0
44
+ end
45
+ end
46
+
47
+ def self.calculate_raw_hue_value(offset, first_color, second_color, max_min_diff)
48
+ offset + ((first_color - second_color).to_f / max_min_diff).round(ROUND_VALUE)
49
+ end
50
+
51
+ # Calculate the a monochromatic value to a given color
52
+ def self.calculate_monochromatic_color(hue_color)
53
+ saturation = hue_color[1]
54
+ value = hue_color[2]
55
+ if saturation > 0.7
56
+ saturation -= MONO_SATURATION
57
+ else
58
+ saturation += MONO_SATURATION
59
+ end
60
+ value -= MONO_VALUE
61
+ [hue_color[0], saturation.round(ROUND_VALUE), value]
62
+ end
63
+
64
+ # rubocop:disable Metrics/AbcSize
65
+ # rubocop:disable Metrics/MethodLength
66
+ def self.hsv_to_rgb(hue, saturation, value)
67
+ hue = hue.to_f / FULL_CIRCLE_DEG
68
+
69
+ hue_i = (hue * 6).to_i
70
+ f = (hue * 6) - hue_i
71
+ p = value * (1 - saturation)
72
+ q = value * (1 - (f * saturation))
73
+ t = value * (1 - ((1 - f) * saturation))
74
+ if hue_i.zero?
75
+ red = value
76
+ green = t
77
+ blue = p
78
+ end
79
+ if hue_i == 1
80
+ red = q
81
+ green = value
82
+ blue = p
83
+ end
84
+ if hue_i == 2
85
+ red = p
86
+ green = value
87
+ blue = t
88
+ end
89
+ if hue_i == 3
90
+ red = p
91
+ green = q
92
+ blue = value
93
+ end
94
+ if hue_i == 4
95
+ red = t
96
+ green = p
97
+ blue = value
98
+ end
99
+ if hue_i == 5
100
+ red = value
101
+ green = p
102
+ blue = q
103
+ end
104
+ [(red * RGB_MAX_VALUE).round.abs, (green * RGB_MAX_VALUE).round.abs, (blue * RGB_MAX_VALUE).round.abs]
105
+ end
106
+ # rubocop:enable Metrics/AbcSize
107
+ # rubocop:enable Metrics/MethodLength
108
+ end
data/lib/color/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ColoR
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
data/lib/color.rb CHANGED
@@ -14,4 +14,14 @@ module ColoR
14
14
  comp_r = [255 - rgb_color[0], 255 - rgb_color[1], 255 - rgb_color[2]]
15
15
  ::RGB.rgb_to_hex(comp_r)
16
16
  end
17
+
18
+ def self.get_monochromatic_color(color)
19
+ raise HexCodeError.new("Not a valid Hex Color"), color unless ::Hex.hex?(color)
20
+
21
+ rgb_color = ::RGB.hex_to_rgb(color)
22
+ hue_color = ::HSV.rgb_to_hsv(rgb_color)
23
+ mono_color = ::HSV.calculate_monochromatic_color(hue_color)
24
+ mono_rgb = ::HSV.hsv_to_rgb(mono_color[0], mono_color[1], mono_color[2])
25
+ ::RGB.rgb_to_hex(mono_rgb)
26
+ end
17
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Complementary_Color
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Hiller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-25 00:00:00.000000000 Z
11
+ date: 2022-06-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Create complementary colors based on a given color.
14
14
  email:
@@ -26,6 +26,7 @@ files:
26
26
  - lib/color.rb
27
27
  - lib/color/error/hex_code_error.rb
28
28
  - lib/color/hex.rb
29
+ - lib/color/hsv.rb
29
30
  - lib/color/rgb.rb
30
31
  - lib/color/version.rb
31
32
  - sig/color.rbs