human_colour 0.2.0 → 0.3.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
  SHA256:
3
- metadata.gz: b48c9c44e725f9a50838c47d15d75fdae3ed1867530731cd7cb7a36fdd9968f7
4
- data.tar.gz: 85940a6afd94a1ec214b75321072b10681b18529a5df0554797f53adf06f756c
3
+ metadata.gz: 47af2da1e39857844b4b6586da5dadb801036478f497a9f112cff41f563c1e70
4
+ data.tar.gz: 8327b50b7b74ce6f111b8d9eac377aca5646d929a718b3fd21084c6514ce6030
5
5
  SHA512:
6
- metadata.gz: 5657ca4c638bc705d22cb39790b40c074da91e62fffd03a3d64ebc08e471b586f0399d752a6c98d32db920b11620c084111ee37cccb739dbac4489bba3fd1660
7
- data.tar.gz: b69e4a4c8fa0e369cb612be81af014904caa7ea36a069273195f404dcdf81848eb4e93506c4e8374dbac682870fbeb3cc1d6eff287a0d044502c3f71df63a004
6
+ metadata.gz: 6e7aaba52e1d446819301ab65bd3fa57a93652a998ac0c81468ef4b000e7e1f784e42bb854dac040d5c1af0bfa64e5e40e1e398bfa6ec39936253c5d6cad9f0d
7
+ data.tar.gz: e9aa06df3f2ca7b42370a0ec7c85297a4cbf050fe6fd4d78c78576ac15045cb1119a53b675f3bd9f48c65dc4b76aa946f112d5ba7afb9fb90882592a7ba2834f
data/README.md CHANGED
@@ -19,12 +19,17 @@ gem install human_colour
19
19
  ## Usage
20
20
 
21
21
  ```ruby
22
+ require "human_colour"
23
+
22
24
  HumanColour.parse("rgb(128,64,0)")
23
25
  #=> "dark orange"
24
26
 
25
- # Return a colour based on the provided locale
27
+ # Return a colour based on the provided locale (:de, :en, :es, :fr, :it, :pt)
26
28
  HumanColour.parse("rgb(128,64,0)", locale: :es)
27
29
  #=> "naranja oscuro"
30
+
31
+ HumanColour.parse("rgb(255, 128, 255", locale: :de)
32
+ #=> "hell lila"
28
33
  ```
29
34
 
30
35
  ![alt text](https://github.com/mconnell/human_colour/blob/main/doc/colours.png?raw=true)
data/doc/colours.png CHANGED
Binary file
@@ -10,6 +10,7 @@ module HumanColour
10
10
  },
11
11
  colour: {
12
12
  red: "red",
13
+ brown: "brown",
13
14
  orange: "orange",
14
15
  yellow: "yellow",
15
16
  green: "green",
@@ -29,6 +30,7 @@ module HumanColour
29
30
  },
30
31
  colour: {
31
32
  red: "rojo",
33
+ brown: "marrón",
32
34
  orange: "naranja",
33
35
  yellow: "amarillo",
34
36
  green: "verde",
@@ -48,6 +50,7 @@ module HumanColour
48
50
  },
49
51
  colour: {
50
52
  red: "rosso",
53
+ brown: "marrone",
51
54
  orange: "arancione",
52
55
  yellow: "giallo",
53
56
  green: "verde",
@@ -67,6 +70,7 @@ module HumanColour
67
70
  },
68
71
  colour: {
69
72
  red: "rouge",
73
+ brown: "brun",
70
74
  orange: "orange",
71
75
  yellow: "jaune",
72
76
  green: "vert",
@@ -86,6 +90,7 @@ module HumanColour
86
90
  },
87
91
  colour: {
88
92
  red: "rot",
93
+ brown: "braun",
89
94
  orange: "orange",
90
95
  yellow: "gelb",
91
96
  green: "grün",
@@ -105,6 +110,7 @@ module HumanColour
105
110
  },
106
111
  colour: {
107
112
  red: "vermelho",
113
+ brown: "marrom",
108
114
  orange: "laranja",
109
115
  yellow: "amarelo",
110
116
  green: "verde",
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HumanColour
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/human_colour.rb CHANGED
@@ -22,8 +22,8 @@ module HumanColour
22
22
  d = delta(red: red, green: green, blue: blue)
23
23
  s = saturation(delta: d, lightness: l)
24
24
  h = hue(delta: d, red: red, green: green, blue: blue)
25
- t = tone(lightness: l, hue: h)
26
- c = colour(saturation: s, hue: h)
25
+ c = colour(saturation: s, hue: h, lightness: l)
26
+ t = tone(lightness: l, hue: h, base: c)
27
27
 
28
28
  localised_tone = LOCALES[locale][:tone][t]
29
29
  localised_colour = LOCALES[locale][:colour][c]
@@ -70,9 +70,12 @@ module HumanColour
70
70
  end
71
71
  private_class_method :hue
72
72
 
73
- def self.tone(lightness:, hue:)
74
- return nil if (260..320).cover?(hue) && lightness >= 0.22 && lightness < 0.28
75
- return :dark if lightness < 0.28
73
+ def self.tone(lightness:, hue:, base:)
74
+ return nil if (260..320).cover?(hue) && lightness.between?(0.22, 0.28)
75
+ return nil if base == :brown
76
+
77
+ # All other hues
78
+ return :dark if lightness < 0.28
76
79
  return :light if lightness > 0.74
77
80
 
78
81
  nil
@@ -80,8 +83,9 @@ module HumanColour
80
83
  private_class_method :tone
81
84
 
82
85
  # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
83
- def self.colour(saturation:, hue:)
86
+ def self.colour(saturation:, hue:, lightness:)
84
87
  return :grey if saturation < 0.15
88
+ return :brown if (15..50).cover?(hue) && lightness < 0.5
85
89
 
86
90
  case hue
87
91
  when 0...15, 355..360 then :red
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: human_colour
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Connell