redgreenblue 0.12.0 → 0.13.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 +4 -4
- data/lib/redgreenblue.rb +2 -2
- data/lib/redgreenblue/cie_1976.rb +3 -3
- data/lib/redgreenblue/lazy.rb +59 -39
- data/lib/redgreenblue/mac.rb +8 -0
- data/lib/redgreenblue/match.rb +21 -0
- data/lib/redgreenblue/os/mac.rb +4 -4
- data/lib/redgreenblue/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65191c26a6dcae9a6bb52abe182d376e0975b79672686120185c9a2b3d49e4e9
|
4
|
+
data.tar.gz: 3fb9dc542660f5edaec8283a2e74ec0687e369e05475bf6840344ca5cca0304f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c0d6a47aa611822dba62189c14ebf38c0ef6315f08ac9b5eb9efe04b28487d2c95105c0e86536cb52fdc9ce36df445d060623a14e99f2dbab34df5e0d10e515
|
7
|
+
data.tar.gz: 756bdaa8c6859c685e51342ee8a6d34e7340ea0580bd79b4487443d97b04629ed1b7c8f1631bf3ac26a5570e6c243aba7f7b931243ea967f07d8437fa223d495
|
data/lib/redgreenblue.rb
CHANGED
@@ -28,7 +28,7 @@ class RGB
|
|
28
28
|
cie_lch_ab_uv(type: :luv)
|
29
29
|
end
|
30
30
|
|
31
|
-
# Returns the
|
31
|
+
# Returns the difference between this color and another color, according to the CIE 1976 delta E formula.
|
32
32
|
#
|
33
33
|
# Based on:
|
34
34
|
# - http://www.brucelindbloom.com/Eqn_DeltaE_CIE76.html
|
@@ -61,7 +61,7 @@ class RGB
|
|
61
61
|
|
62
62
|
f = [ x / xr, y / yr, z / zr ].map { |v|
|
63
63
|
if v > ( 216.0 / 24389 )
|
64
|
-
|
64
|
+
Math.cbrt v
|
65
65
|
else
|
66
66
|
( 24389.0 / 27 * v + 16 ) / 116.0
|
67
67
|
end
|
@@ -97,7 +97,7 @@ class RGB
|
|
97
97
|
|
98
98
|
[
|
99
99
|
l.round(8),
|
100
|
-
c = (
|
100
|
+
c = Math.hypot(v1, v2).round(8),
|
101
101
|
c == 0 ? nil : ( Math.atan2(v2, v1) * 180.0 / Math::PI ).modulo(360).round(8)
|
102
102
|
]
|
103
103
|
end
|
data/lib/redgreenblue/lazy.rb
CHANGED
@@ -1,53 +1,73 @@
|
|
1
1
|
class RGB
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
3
|
+
#----------------------------------------------------------------------#
|
4
|
+
# Class Methods #
|
5
|
+
#----------------------------------------------------------------------#
|
7
6
|
|
8
|
-
|
9
|
-
def self.black
|
10
|
-
new(0,0,0)
|
11
|
-
end
|
7
|
+
class << self
|
12
8
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
new(lightness, lightness, lightness)
|
18
|
-
end
|
9
|
+
# Creates a white RGB object.
|
10
|
+
def white
|
11
|
+
new(1,1,1)
|
12
|
+
end
|
19
13
|
|
20
|
-
|
21
|
-
|
14
|
+
# Creates a black RGB object.
|
15
|
+
def black
|
16
|
+
new(0,0,0)
|
17
|
+
end
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
# Creates a grey RGB object. Defaults to lightness 0.5, a middle grey. Black equals grey(0), white equals grey(1).
|
20
|
+
#
|
21
|
+
# ::gray is an alias for ::grey.
|
22
|
+
def grey(lightness=0.5)
|
23
|
+
new(lightness, lightness, lightness)
|
24
|
+
end
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
new(0,1,0)
|
31
|
-
end
|
26
|
+
# Alias gray for grey.
|
27
|
+
alias gray grey
|
32
28
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
# Creates a pure red RGB object.
|
30
|
+
def red
|
31
|
+
new(1,0,0)
|
32
|
+
end
|
37
33
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
34
|
+
# Creates a pure green RGB object.
|
35
|
+
def green
|
36
|
+
new(0,1,0)
|
37
|
+
end
|
42
38
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
39
|
+
# Creates a pure blue RGB object.
|
40
|
+
def blue
|
41
|
+
new(0,0,1)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Creates a yellow RGB object.
|
45
|
+
def yellow
|
46
|
+
new(1,1,0)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Creates a cyan RGB object.
|
50
|
+
def cyan
|
51
|
+
new(0,1,1)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Creates a magenta RGB object.
|
55
|
+
def magenta
|
56
|
+
new(1,0,1)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Returns the 8 corners of the RGB cube.
|
60
|
+
def corners
|
61
|
+
[ black, red, yellow, green, cyan, blue, magenta, white ]
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns the centre of the RGB cube.
|
65
|
+
def centre
|
66
|
+
grey
|
67
|
+
end
|
68
|
+
|
69
|
+
alias center centre
|
47
70
|
|
48
|
-
# Creates a magenta RGB object.
|
49
|
-
def self.magenta
|
50
|
-
new(1,0,1)
|
51
71
|
end
|
52
72
|
|
53
73
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class RGB
|
2
|
+
|
3
|
+
# Matches this color to a set of colors by calculating their euclidean distance.
|
4
|
+
#
|
5
|
+
# Returns the given set of colors with their distance from this color, sorted by distance (nearest color first).
|
6
|
+
# @example What is nearer: red, grey or white?
|
7
|
+
# RGB.hex('f9c').match_distance [RGB.red, RGB.grey, RGB.white]
|
8
|
+
def match_distance(others)
|
9
|
+
others.map { |c| [ c, distance(c) ] }.sort_by { |a| a[1] }
|
10
|
+
end
|
11
|
+
|
12
|
+
# Matches this color to a set of colors using the CIE 1976 delta E formula.
|
13
|
+
#
|
14
|
+
# Returns the given set of colors with their difference from this color, sorted by difference (nearest color first).
|
15
|
+
# @example Find the 3 nearest CSS named colors
|
16
|
+
# RGB.hex('f9c').match_de76(RGB.css).first(3)
|
17
|
+
def match_de76(others)
|
18
|
+
others.map { |c| [ c, de76(c) ] }.sort_by { |a| a[1] }
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/lib/redgreenblue/os/mac.rb
CHANGED
@@ -3,7 +3,7 @@ class RGB
|
|
3
3
|
# On Mac OS, shows the color picker to choose a color for the RGB object.
|
4
4
|
# Not available on other platforms.
|
5
5
|
def pick
|
6
|
-
result = RGB.mac_choose(
|
6
|
+
result = RGB.mac_choose(self)
|
7
7
|
if result
|
8
8
|
self.rrggbb = result
|
9
9
|
end
|
@@ -14,7 +14,7 @@ class RGB
|
|
14
14
|
#
|
15
15
|
# If no default color is specified, the picker defaults to a middle grey.
|
16
16
|
def self.pick(default_color=RGB.new)
|
17
|
-
result = RGB.mac_choose(default_color
|
17
|
+
result = RGB.mac_choose(default_color)
|
18
18
|
if result
|
19
19
|
RGB.rrggbb result
|
20
20
|
else
|
@@ -32,7 +32,7 @@ class RGB
|
|
32
32
|
#
|
33
33
|
# Applescript command documented here:
|
34
34
|
# Standard Additions -> User Interaction -> choose color
|
35
|
-
def self.mac_choose(
|
35
|
+
def self.mac_choose(default_color)
|
36
36
|
|
37
37
|
app = case ENV['TERM_PROGRAM']
|
38
38
|
when /iTerm\.app/
|
@@ -44,7 +44,7 @@ class RGB
|
|
44
44
|
script = <<~ENDSCRIPT
|
45
45
|
tell application "#{app}"
|
46
46
|
try
|
47
|
-
return choose color default color
|
47
|
+
return choose color default color #{default_color.applescript}
|
48
48
|
on error
|
49
49
|
return ""
|
50
50
|
end try
|
data/lib/redgreenblue/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redgreenblue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lllist.eu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09
|
11
|
+
date: 2020-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -34,6 +34,8 @@ files:
|
|
34
34
|
- lib/redgreenblue/inspect.rb
|
35
35
|
- lib/redgreenblue/int.rb
|
36
36
|
- lib/redgreenblue/lazy.rb
|
37
|
+
- lib/redgreenblue/mac.rb
|
38
|
+
- lib/redgreenblue/match.rb
|
37
39
|
- lib/redgreenblue/math.rb
|
38
40
|
- lib/redgreenblue/misc.rb
|
39
41
|
- lib/redgreenblue/mix.rb
|