redgreenblue 0.16.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redgreenblue/24bit.rb +3 -6
- data/lib/redgreenblue/48bit.rb +2 -5
- data/lib/redgreenblue/base.rb +1 -1
- data/lib/redgreenblue/bgr24bit.rb +2 -5
- data/lib/redgreenblue/cie_1931.rb +56 -8
- data/lib/redgreenblue/gpl.rb +2 -9
- data/lib/redgreenblue/hex.rb +2 -5
- data/lib/redgreenblue/hsb.rb +2 -13
- data/lib/redgreenblue/hsl.rb +2 -13
- data/lib/redgreenblue/hsv.rb +2 -13
- data/lib/redgreenblue/hsx_shared.rb +0 -8
- data/lib/redgreenblue/inspect.rb +11 -3
- data/lib/redgreenblue/int.rb +2 -5
- data/lib/redgreenblue/lazy.rb +18 -24
- data/lib/redgreenblue/math.rb +11 -0
- data/lib/redgreenblue/misc.rb +0 -3
- data/lib/redgreenblue/mix.rb +39 -3
- data/lib/redgreenblue/ostwald.rb +1 -1
- data/lib/redgreenblue/random.rb +0 -3
- data/lib/redgreenblue/rgb565.rb +0 -3
- data/lib/redgreenblue/version.rb +1 -1
- data/lib/redgreenblue/web.rb +0 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7bd0c8570ea98fb428ff9b0213cbdbcfb406a7ec93174e71152b367221091a8
|
4
|
+
data.tar.gz: 802d9d4c8fba0af75a7d1095f24ae81f23d5e5338674b68a69ba0b023cd092bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8af18bacea35e6b732330b7d0a9d907ed90d41951c932307474bffef02e8d6965230441c2322d188314d4280ebbe678b0e56780ede151b5e0a61db2f1f41dc0
|
7
|
+
data.tar.gz: 6b749f770956cada8c6e7fa82c5ec8255ee6081ee98746bac71182572fd5d67ae83c069db4798b2b920c3d5d01c4e39c0cf1ad5b16e5c92a7ae9956d97923f90
|
data/lib/redgreenblue/24bit.rb
CHANGED
@@ -44,7 +44,7 @@ class RGB::Color
|
|
44
44
|
self.r, self.g, self.b = rgb.flatten
|
45
45
|
end
|
46
46
|
|
47
|
-
# Creates a new Color
|
47
|
+
# Creates a new RGB::Color from red, green, and blue components as integers in the range 0..255 (three 8-bit values).
|
48
48
|
def self.rgb(*rgb)
|
49
49
|
c = self.new
|
50
50
|
c.rgb = rgb
|
@@ -57,22 +57,19 @@ class RGB::Color
|
|
57
57
|
self
|
58
58
|
end
|
59
59
|
|
60
|
-
# Creates a new RGB
|
60
|
+
# Creates a new RGB::Color containing the nearest 24-bit color.
|
61
61
|
def snap
|
62
62
|
RGB.rgb rgb
|
63
63
|
end
|
64
64
|
|
65
65
|
end
|
66
66
|
|
67
|
-
#----------------------------------------------------------------------#
|
68
|
-
# Module Methods #
|
69
|
-
#----------------------------------------------------------------------#
|
70
67
|
|
71
68
|
module RGB
|
72
69
|
|
73
70
|
class << self
|
74
71
|
|
75
|
-
# Creates a new Color
|
72
|
+
# Creates a new RGB::Color from red, green, and blue components as integers in the range 0..255 (three 8-bit values).
|
76
73
|
def rgb(*rgb)
|
77
74
|
Color.rgb(*rgb)
|
78
75
|
end
|
data/lib/redgreenblue/48bit.rb
CHANGED
@@ -44,7 +44,7 @@ class RGB::Color
|
|
44
44
|
self.rr, self.gg, self.bb = rrggbb.flatten
|
45
45
|
end
|
46
46
|
|
47
|
-
# Creates a new Color
|
47
|
+
# Creates a new RGB::Color from red, green, and blue components as integers in the range 0..65535 (three 16-bit values).
|
48
48
|
def self.rrggbb(*rrggbb)
|
49
49
|
c = self.new
|
50
50
|
c.rrggbb = rrggbb
|
@@ -53,15 +53,12 @@ class RGB::Color
|
|
53
53
|
|
54
54
|
end
|
55
55
|
|
56
|
-
#----------------------------------------------------------------------#
|
57
|
-
# Module Methods #
|
58
|
-
#----------------------------------------------------------------------#
|
59
56
|
|
60
57
|
module RGB
|
61
58
|
|
62
59
|
class << self
|
63
60
|
|
64
|
-
# Creates a new Color
|
61
|
+
# Creates a new RGB::Color from red, green, and blue components as integers in the range 0..65535 (three 16-bit values).
|
65
62
|
def rrggbb(*rrggbb)
|
66
63
|
Color.rrggbb(*rrggbb)
|
67
64
|
end
|
data/lib/redgreenblue/base.rb
CHANGED
@@ -88,7 +88,7 @@ module RGB
|
|
88
88
|
|
89
89
|
class << self
|
90
90
|
|
91
|
-
# Creates a new Color
|
91
|
+
# Creates a new RGB::Color from red, green, and blue components as three values between 0 and 1.
|
92
92
|
def new(*a)
|
93
93
|
Color.new(*a)
|
94
94
|
end
|
@@ -10,7 +10,7 @@ class RGB::Color
|
|
10
10
|
self.b, self.g, self.r = bgr_string.unpack('C3')
|
11
11
|
end
|
12
12
|
|
13
|
-
# Creates a new RGB::Color
|
13
|
+
# Creates a new RGB::Color from BGR24 data (a 3-byte string).
|
14
14
|
def self.bgr24(bgr)
|
15
15
|
c = self.new
|
16
16
|
c.bgr24 = bgr
|
@@ -19,15 +19,12 @@ class RGB::Color
|
|
19
19
|
|
20
20
|
end
|
21
21
|
|
22
|
-
#----------------------------------------------------------------------#
|
23
|
-
# Module Methods #
|
24
|
-
#----------------------------------------------------------------------#
|
25
22
|
|
26
23
|
module RGB
|
27
24
|
|
28
25
|
class << self
|
29
26
|
|
30
|
-
# Creates a new RGB::Color
|
27
|
+
# Creates a new RGB::Color from BGR24 data (a 3-byte string).
|
31
28
|
def bgr24(bgr)
|
32
29
|
Color.bgr24(bgr)
|
33
30
|
end
|
@@ -1,5 +1,20 @@
|
|
1
1
|
class RGB::Color
|
2
2
|
|
3
|
+
class << self
|
4
|
+
|
5
|
+
# Creates a new RGB::Color from CIE 1931 XYZ values.
|
6
|
+
#
|
7
|
+
# Assumes the XYZ values are relative to D65 reference white, the same as used in sRGB.
|
8
|
+
def cie_xyz(*a)
|
9
|
+
c = self.new
|
10
|
+
c.cie_xyz = a
|
11
|
+
c
|
12
|
+
end
|
13
|
+
|
14
|
+
alias xyz cie_xyz
|
15
|
+
|
16
|
+
end
|
17
|
+
|
3
18
|
# Returns CIE 1931 XYZ values for the RGB::Color object.
|
4
19
|
#
|
5
20
|
# Based on:
|
@@ -11,41 +26,74 @@ class RGB::Color
|
|
11
26
|
r, g, b = linear_values
|
12
27
|
|
13
28
|
[
|
14
|
-
|
15
29
|
r * 0.4124_5643_9090 + g * 0.3575_7607_7644 + b * 0.1804_3748_3266,
|
16
30
|
r * 0.2126_7285_1406 + g * 0.7151_5215_5288 + b * 0.0721_7499_3307,
|
17
31
|
r * 0.0193_3389_5582 + g * 0.1191_9202_5881 + b * 0.9503_0407_8536
|
18
|
-
|
19
32
|
].map { |v| round ? v.round(8) : v }
|
20
33
|
end
|
21
34
|
|
22
35
|
alias xyz cie_xyz
|
23
36
|
|
37
|
+
# Sets the red, green, and blue values by converting the given CIE 1931 XYZ values to RGB.
|
38
|
+
#
|
39
|
+
# Assumes the XYZ values are relative to D65 reference white, the same as used in sRGB.
|
40
|
+
#
|
41
|
+
# Based on:
|
42
|
+
# - http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_RGB.html
|
43
|
+
# XYZ to sRGB matrix for D65 reference white calculated with Javascript by Bruce Lindbloom:
|
44
|
+
# - http://www.brucelindbloom.com/ColorCalculator.html
|
45
|
+
def cie_xyz=(*a)
|
46
|
+
x, y, z = a.flatten
|
47
|
+
self.linear_values = [
|
48
|
+
x * 3.2404_5416_2114 + y * -1.5371_3851_2798 + z * -0.498_5314_09556,
|
49
|
+
x * -0.9692_6603_0505 + y * 1.8760_1084_5447 + z * 0.0415_5601_7530,
|
50
|
+
x * 0.0556_4343_0959 + y * -0.2040_2591_3517 + z * 1.0572_2518_8223
|
51
|
+
]
|
52
|
+
end
|
53
|
+
|
54
|
+
alias xyz= cie_xyz=
|
55
|
+
|
24
56
|
# Returns CIE 1931 xyY values for the RGB::Color object.
|
25
57
|
#
|
26
58
|
# Based on:
|
27
59
|
# - https://en.wikipedia.org/wiki/CIE_1931_color_space
|
28
60
|
# - http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_xyY.html
|
29
61
|
# - https://ninedegreesbelow.com/photography/xyz-rgb.html
|
30
|
-
def cie_xyy
|
62
|
+
def cie_xyy(round: true)
|
31
63
|
x, y, z = cie_xyz(round: false)
|
32
64
|
|
33
65
|
[
|
34
|
-
|
35
66
|
x / ( x + y + z ),
|
36
67
|
y / ( x + y + z ),
|
37
68
|
y
|
38
|
-
|
39
|
-
].map { |v| v.round(8) }
|
69
|
+
].map { |v| round ? v.round(8) : v }
|
40
70
|
end
|
41
71
|
|
42
72
|
alias xyy cie_xyy
|
43
73
|
|
44
74
|
# Returns CIE 1931 xy values for the RGB::Color object.
|
45
|
-
def cie_xy
|
46
|
-
cie_xyy[0..1]
|
75
|
+
def cie_xy(round: true)
|
76
|
+
cie_xyy(round: round)[0..1]
|
47
77
|
end
|
48
78
|
|
49
79
|
alias xy cie_xy
|
50
80
|
|
51
81
|
end
|
82
|
+
|
83
|
+
|
84
|
+
module RGB
|
85
|
+
|
86
|
+
class << self
|
87
|
+
|
88
|
+
# Creates a new RGB::Color from CIE 1931 XYZ values.
|
89
|
+
#
|
90
|
+
# Assumes the XYZ values are relative to D65 reference white, the same as used in sRGB.
|
91
|
+
def cie_xyz(*a)
|
92
|
+
RGB::Color.cie_xyz(a)
|
93
|
+
end
|
94
|
+
|
95
|
+
alias xyz cie_xyz
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
data/lib/redgreenblue/gpl.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
class RGB::Color
|
2
2
|
|
3
|
-
#----------------------------------------------------------------------#
|
4
|
-
# Class Methods #
|
5
|
-
#----------------------------------------------------------------------#
|
6
|
-
|
7
3
|
class << self
|
8
4
|
|
9
|
-
# Creates a new RGB::Color
|
5
|
+
# Creates a new RGB::Color from a line of gpl (Gimp color palette) input. Returns nil if not successful.
|
10
6
|
#
|
11
7
|
# @example
|
12
8
|
# RGB::Color.gpl "255 153 204\tpink"
|
@@ -22,9 +18,6 @@ class RGB::Color
|
|
22
18
|
|
23
19
|
end
|
24
20
|
|
25
|
-
#----------------------------------------------------------------------#
|
26
|
-
# Instance Methods #
|
27
|
-
#----------------------------------------------------------------------#
|
28
21
|
|
29
22
|
# Returns the color in the format used in .gpl files (Gimp color palettes), including its name (if present).
|
30
23
|
#
|
@@ -41,7 +34,7 @@ module RGB
|
|
41
34
|
|
42
35
|
class << self
|
43
36
|
|
44
|
-
# Creates a new RGB::Color
|
37
|
+
# Creates a new RGB::Color from a line of gpl (Gimp color palette) input. Returns nil if not successful.
|
45
38
|
#
|
46
39
|
# @example
|
47
40
|
# RGB.gpl "255 153 204\tpink"
|
data/lib/redgreenblue/hex.rb
CHANGED
@@ -28,11 +28,8 @@ class RGB::Color
|
|
28
28
|
'%02x%02x%02x' % [ r, g, b ]
|
29
29
|
end
|
30
30
|
|
31
|
-
#----------------------------------------------------------------------#
|
32
|
-
# Class Methods #
|
33
|
-
#----------------------------------------------------------------------#
|
34
31
|
|
35
|
-
# Creates a new Color
|
32
|
+
# Creates a new RGB::Color from a 6- or 3-digit hexadecimal string representing red, green, and blue.
|
36
33
|
#
|
37
34
|
# The string may include a '#' prefix.
|
38
35
|
def self.hex(hex_string)
|
@@ -49,7 +46,7 @@ module RGB
|
|
49
46
|
|
50
47
|
class << self
|
51
48
|
|
52
|
-
# Creates a new Color
|
49
|
+
# Creates a new RGB::Color from a 6- or 3-digit hexadecimal string representing red, green, and blue.
|
53
50
|
#
|
54
51
|
# The string may include a '#' prefix.
|
55
52
|
def hex(hex_string)
|
data/lib/redgreenblue/hsb.rb
CHANGED
@@ -2,21 +2,13 @@ require 'redgreenblue/hsv'
|
|
2
2
|
|
3
3
|
class RGB::Color
|
4
4
|
|
5
|
-
#----------------------------------------------------------------------#
|
6
|
-
# Class Methods #
|
7
|
-
#----------------------------------------------------------------------#
|
8
|
-
|
9
5
|
class << self
|
10
6
|
|
11
|
-
# Creates a new RGB::Color
|
7
|
+
# Creates a new RGB::Color from HSB values: hue (0..360), saturation (0..1), and brightness (0..1).
|
12
8
|
alias hsb hsv
|
13
9
|
|
14
10
|
end
|
15
11
|
|
16
|
-
#----------------------------------------------------------------------#
|
17
|
-
# Instance Methods #
|
18
|
-
#----------------------------------------------------------------------#
|
19
|
-
|
20
12
|
# Returns color as HSB:
|
21
13
|
# hue (0..360), saturation (0..1), brightness (0..1).
|
22
14
|
# When saturation is 0, hue is nil.
|
@@ -60,15 +52,12 @@ class RGB::Color
|
|
60
52
|
|
61
53
|
end
|
62
54
|
|
63
|
-
#----------------------------------------------------------------------#
|
64
|
-
# Module Methods #
|
65
|
-
#----------------------------------------------------------------------#
|
66
55
|
|
67
56
|
module RGB
|
68
57
|
|
69
58
|
class << self
|
70
59
|
|
71
|
-
# Creates a new RGB::Color
|
60
|
+
# Creates a new RGB::Color from HSB values: hue (0..360), saturation (0..1), and brightness (0..1).
|
72
61
|
alias hsb hsv
|
73
62
|
|
74
63
|
end
|
data/lib/redgreenblue/hsl.rb
CHANGED
@@ -3,13 +3,9 @@ require 'redgreenblue/math'
|
|
3
3
|
|
4
4
|
class RGB::Color
|
5
5
|
|
6
|
-
#----------------------------------------------------------------------#
|
7
|
-
# Class Methods #
|
8
|
-
#----------------------------------------------------------------------#
|
9
|
-
|
10
6
|
class << self
|
11
7
|
|
12
|
-
# Creates a new RGB::Color
|
8
|
+
# Creates a new RGB::Color from HSL values: hue (0..360), saturation (0..1), and lightness (0..1).
|
13
9
|
def hsl(*a)
|
14
10
|
new hsl_to_values(*a)
|
15
11
|
end
|
@@ -23,10 +19,6 @@ class RGB::Color
|
|
23
19
|
|
24
20
|
end
|
25
21
|
|
26
|
-
#----------------------------------------------------------------------#
|
27
|
-
# Instance Methods #
|
28
|
-
#----------------------------------------------------------------------#
|
29
|
-
|
30
22
|
# Returns color as HSL:
|
31
23
|
# hue (0..360), saturation (0..1), lightness (0..1).
|
32
24
|
# When saturation is 0, hue is nil.
|
@@ -95,15 +87,12 @@ class RGB::Color
|
|
95
87
|
|
96
88
|
end
|
97
89
|
|
98
|
-
#----------------------------------------------------------------------#
|
99
|
-
# Module Methods #
|
100
|
-
#----------------------------------------------------------------------#
|
101
90
|
|
102
91
|
module RGB
|
103
92
|
|
104
93
|
class << self
|
105
94
|
|
106
|
-
# Creates a new RGB::Color
|
95
|
+
# Creates a new RGB::Color from HSL values: hue (0..360), saturation (0..1), and lightness (0..1).
|
107
96
|
def hsl(*a)
|
108
97
|
Color.hsl(*a)
|
109
98
|
end
|
data/lib/redgreenblue/hsv.rb
CHANGED
@@ -3,13 +3,9 @@ require 'redgreenblue/math'
|
|
3
3
|
|
4
4
|
class RGB::Color
|
5
5
|
|
6
|
-
#----------------------------------------------------------------------#
|
7
|
-
# Class Methods #
|
8
|
-
#----------------------------------------------------------------------#
|
9
|
-
|
10
6
|
class << self
|
11
7
|
|
12
|
-
# Creates a new RGB::Color
|
8
|
+
# Creates a new RGB::Color from HSV values: hue (0..360), saturation (0..1), and value (0..1).
|
13
9
|
def hsv(*a)
|
14
10
|
new hsv_to_values(*a)
|
15
11
|
end
|
@@ -23,10 +19,6 @@ class RGB::Color
|
|
23
19
|
|
24
20
|
end
|
25
21
|
|
26
|
-
#----------------------------------------------------------------------#
|
27
|
-
# Instance Methods #
|
28
|
-
#----------------------------------------------------------------------#
|
29
|
-
|
30
22
|
# Returns color as HSV:
|
31
23
|
# hue (0..360), saturation (0..1), value (0..1).
|
32
24
|
# When saturation is 0, hue is nil.
|
@@ -95,15 +87,12 @@ class RGB::Color
|
|
95
87
|
|
96
88
|
end
|
97
89
|
|
98
|
-
#----------------------------------------------------------------------#
|
99
|
-
# Module Methods #
|
100
|
-
#----------------------------------------------------------------------#
|
101
90
|
|
102
91
|
module RGB
|
103
92
|
|
104
93
|
class << self
|
105
94
|
|
106
|
-
# Creates a new RGB::Color
|
95
|
+
# Creates a new RGB::Color from HSV values: hue (0..360), saturation (0..1), and value (0..1).
|
107
96
|
def hsv(*a)
|
108
97
|
Color.hsv(*a)
|
109
98
|
end
|
@@ -1,9 +1,5 @@
|
|
1
1
|
class RGB::Color
|
2
2
|
|
3
|
-
#----------------------------------------------------------------------#
|
4
|
-
# Class Methods #
|
5
|
-
#----------------------------------------------------------------------#
|
6
|
-
|
7
3
|
class << self
|
8
4
|
|
9
5
|
private
|
@@ -48,10 +44,6 @@ class RGB::Color
|
|
48
44
|
|
49
45
|
end
|
50
46
|
|
51
|
-
#----------------------------------------------------------------------#
|
52
|
-
# Instance Methods #
|
53
|
-
#----------------------------------------------------------------------#
|
54
|
-
|
55
47
|
private
|
56
48
|
|
57
49
|
# Compute HSL, HSV, and chroma.
|
data/lib/redgreenblue/inspect.rb
CHANGED
@@ -26,6 +26,17 @@ class RGB::Color
|
|
26
26
|
_inspect_swatch + ( name ? ' ' + name : '' )
|
27
27
|
end
|
28
28
|
|
29
|
+
def _inspect_wilhelm
|
30
|
+
_inspect_short +
|
31
|
+
if h = hsl_h
|
32
|
+
" (H:%7.3f %s \e[0m" % [h, ostwald_color.terminal_background]
|
33
|
+
else
|
34
|
+
' (H: - '
|
35
|
+
end +
|
36
|
+
' C:%5.3f W:%5.3f K:%5.3f)' % cwk +
|
37
|
+
( name ? ' ' + name : '' )
|
38
|
+
end
|
39
|
+
|
29
40
|
public
|
30
41
|
|
31
42
|
# Returns a programmer-friendly representation of the object.
|
@@ -42,9 +53,6 @@ class RGB::Color
|
|
42
53
|
|
43
54
|
end
|
44
55
|
|
45
|
-
#----------------------------------------------------------------------#
|
46
|
-
# Module Methods #
|
47
|
-
#----------------------------------------------------------------------#
|
48
56
|
|
49
57
|
module RGB
|
50
58
|
|
data/lib/redgreenblue/int.rb
CHANGED
@@ -5,7 +5,7 @@ class RGB::Color
|
|
5
5
|
( r << 16 ) + ( g << 8 ) + b
|
6
6
|
end
|
7
7
|
|
8
|
-
# Creates a new RGB::Color
|
8
|
+
# Creates a new RGB::Color from a 24-bit integer in the range 0..16777215.
|
9
9
|
def self.at(number)
|
10
10
|
n = number.to_i
|
11
11
|
if (0..16777215) === n
|
@@ -21,15 +21,12 @@ class RGB::Color
|
|
21
21
|
|
22
22
|
end
|
23
23
|
|
24
|
-
#----------------------------------------------------------------------#
|
25
|
-
# Module Methods #
|
26
|
-
#----------------------------------------------------------------------#
|
27
24
|
|
28
25
|
module RGB
|
29
26
|
|
30
27
|
class << self
|
31
28
|
|
32
|
-
# Creates a new RGB::Color
|
29
|
+
# Creates a new RGB::Color from a 24-bit integer in the range 0..16777215.
|
33
30
|
def at(number)
|
34
31
|
Color.at(number)
|
35
32
|
end
|
data/lib/redgreenblue/lazy.rb
CHANGED
@@ -1,22 +1,19 @@
|
|
1
1
|
class RGB::Color
|
2
2
|
|
3
|
-
#----------------------------------------------------------------------#
|
4
|
-
# Class Methods #
|
5
|
-
#----------------------------------------------------------------------#
|
6
3
|
|
7
4
|
class << self
|
8
5
|
|
9
|
-
# Creates a white RGB::Color
|
6
|
+
# Creates a white RGB::Color.
|
10
7
|
def white
|
11
8
|
new(1,1,1)
|
12
9
|
end
|
13
10
|
|
14
|
-
# Creates a black RGB::Color
|
11
|
+
# Creates a black RGB::Color.
|
15
12
|
def black
|
16
13
|
new(0,0,0)
|
17
14
|
end
|
18
15
|
|
19
|
-
# Creates a grey RGB::Color
|
16
|
+
# Creates a grey RGB::Color. Defaults to lightness 0.5, a middle grey. Black equals grey(0), white equals grey(1).
|
20
17
|
#
|
21
18
|
# ::gray is an alias for ::grey.
|
22
19
|
def grey(lightness=0.5)
|
@@ -26,32 +23,32 @@ class RGB::Color
|
|
26
23
|
# Alias gray for grey.
|
27
24
|
alias gray grey
|
28
25
|
|
29
|
-
# Creates a pure red RGB::Color
|
26
|
+
# Creates a pure red RGB::Color.
|
30
27
|
def red
|
31
28
|
new(1,0,0)
|
32
29
|
end
|
33
30
|
|
34
|
-
# Creates a pure green RGB::Color
|
31
|
+
# Creates a pure green RGB::Color.
|
35
32
|
def green
|
36
33
|
new(0,1,0)
|
37
34
|
end
|
38
35
|
|
39
|
-
# Creates a pure blue RGB::Color
|
36
|
+
# Creates a pure blue RGB::Color.
|
40
37
|
def blue
|
41
38
|
new(0,0,1)
|
42
39
|
end
|
43
40
|
|
44
|
-
# Creates a yellow RGB::Color
|
41
|
+
# Creates a yellow RGB::Color.
|
45
42
|
def yellow
|
46
43
|
new(1,1,0)
|
47
44
|
end
|
48
45
|
|
49
|
-
# Creates a cyan RGB::Color
|
46
|
+
# Creates a cyan RGB::Color.
|
50
47
|
def cyan
|
51
48
|
new(0,1,1)
|
52
49
|
end
|
53
50
|
|
54
|
-
# Creates a magenta RGB::Color
|
51
|
+
# Creates a magenta RGB::Color.
|
55
52
|
def magenta
|
56
53
|
new(1,0,1)
|
57
54
|
end
|
@@ -72,25 +69,22 @@ class RGB::Color
|
|
72
69
|
|
73
70
|
end
|
74
71
|
|
75
|
-
#----------------------------------------------------------------------#
|
76
|
-
# Module Methods #
|
77
|
-
#----------------------------------------------------------------------#
|
78
72
|
|
79
73
|
module RGB
|
80
74
|
|
81
75
|
class << self
|
82
76
|
|
83
|
-
# Creates a white RGB::Color
|
77
|
+
# Creates a white RGB::Color.
|
84
78
|
def white
|
85
79
|
Color.white
|
86
80
|
end
|
87
81
|
|
88
|
-
# Creates a black RGB::Color
|
82
|
+
# Creates a black RGB::Color.
|
89
83
|
def black
|
90
84
|
Color.black
|
91
85
|
end
|
92
86
|
|
93
|
-
# Creates a grey RGB::Color
|
87
|
+
# Creates a grey RGB::Color. Defaults to lightness 0.5, a middle grey. Black equals grey(0), white equals grey(1).
|
94
88
|
#
|
95
89
|
# ::gray is an alias for ::grey.
|
96
90
|
def grey(lightness=0.5)
|
@@ -100,32 +94,32 @@ module RGB
|
|
100
94
|
# Alias gray for grey.
|
101
95
|
alias gray grey
|
102
96
|
|
103
|
-
# Creates a pure red RGB::Color
|
97
|
+
# Creates a pure red RGB::Color.
|
104
98
|
def red
|
105
99
|
Color.red
|
106
100
|
end
|
107
101
|
|
108
|
-
# Creates a pure green RGB::Color
|
102
|
+
# Creates a pure green RGB::Color.
|
109
103
|
def green
|
110
104
|
Color.green
|
111
105
|
end
|
112
106
|
|
113
|
-
# Creates a pure blue RGB::Color
|
107
|
+
# Creates a pure blue RGB::Color.
|
114
108
|
def blue
|
115
109
|
Color.blue
|
116
110
|
end
|
117
111
|
|
118
|
-
# Creates a yellow RGB::Color
|
112
|
+
# Creates a yellow RGB::Color.
|
119
113
|
def yellow
|
120
114
|
Color.yellow
|
121
115
|
end
|
122
116
|
|
123
|
-
# Creates a cyan RGB::Color
|
117
|
+
# Creates a cyan RGB::Color.
|
124
118
|
def cyan
|
125
119
|
Color.cyan
|
126
120
|
end
|
127
121
|
|
128
|
-
# Creates a magenta RGB::Color
|
122
|
+
# Creates a magenta RGB::Color.
|
129
123
|
def magenta
|
130
124
|
Color.magenta
|
131
125
|
end
|
data/lib/redgreenblue/math.rb
CHANGED
@@ -2,6 +2,17 @@ class RGB::Color
|
|
2
2
|
|
3
3
|
private
|
4
4
|
|
5
|
+
# Returns shortest angle of travel (rotation)
|
6
|
+
# to move between 2 points on a circle.
|
7
|
+
#
|
8
|
+
# Some discussions here:
|
9
|
+
# - https://stackoverflow.com/questions/9505862/
|
10
|
+
# - https://stackoverflow.com/questions/7428718/
|
11
|
+
def angle_of_travel(source, destination)
|
12
|
+
angle = destination - source
|
13
|
+
(angle.abs > 180) ? (angle + (angle.negative? ? 360 : -360)) : angle
|
14
|
+
end
|
15
|
+
|
5
16
|
def zip_add(a,b)
|
6
17
|
a.zip(b).map { |ab| ( ab[0] || 0 ) + ab[1] }
|
7
18
|
end
|
data/lib/redgreenblue/misc.rb
CHANGED
data/lib/redgreenblue/mix.rb
CHANGED
@@ -39,10 +39,9 @@ class RGB::Color
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
# Returns a
|
42
|
+
# Returns a number of colors, gradually changing from this color to another color.
|
43
43
|
#
|
44
|
-
# The resulting colors are spaced evenly in the RGB color space
|
45
|
-
# You will likely experience these colors as not exactly evenly spaced.
|
44
|
+
# The resulting colors are spaced evenly in the RGB color space.
|
46
45
|
def steps(another,step_count=1,include_begin=false)
|
47
46
|
# origin (self, optional)
|
48
47
|
( include_begin ? [self.dup] : [] ) +
|
@@ -52,6 +51,22 @@ class RGB::Color
|
|
52
51
|
[another.dup]
|
53
52
|
end
|
54
53
|
|
54
|
+
# Returns a number of colors, gradually changing from this color to another color.
|
55
|
+
#
|
56
|
+
# The resulting colors are spaced evenly by their HSL values (hue, saturation, and lightness).
|
57
|
+
def steps_hsl(another,step_count=1,include_begin=false)
|
58
|
+
steps_hsx(another,step_count,include_begin, :hsl)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns a number of colors, gradually changing from this color to another color.
|
62
|
+
#
|
63
|
+
# The resulting colors are spaced evenly by their HSV values (hue, saturation, and value).
|
64
|
+
def steps_hsv(another,step_count=1,include_begin=false)
|
65
|
+
steps_hsx(another,step_count,include_begin, :hsv)
|
66
|
+
end
|
67
|
+
|
68
|
+
alias steps_hsb steps_hsv
|
69
|
+
|
55
70
|
private
|
56
71
|
|
57
72
|
def mix_values(some_values, portion)
|
@@ -62,4 +77,25 @@ class RGB::Color
|
|
62
77
|
( blue * (1 - portion) ) + ( some_values[2] * portion )
|
63
78
|
]
|
64
79
|
end
|
80
|
+
|
81
|
+
def steps_hsx(another,step_count=1,include_begin=false,type)
|
82
|
+
raise NotImplementedError unless [:hsl, :hsv].include? type
|
83
|
+
src_hsx = self.send(type)
|
84
|
+
dest_hsx = another.send(type)
|
85
|
+
|
86
|
+
# Take care of achromatic origin/destination
|
87
|
+
src_hsx[0] = ( dest_hsx[0] || 0 ) unless src_hsx[0]
|
88
|
+
dest_hsx[0] = ( src_hsx[0] || 0 ) unless dest_hsx[0]
|
89
|
+
|
90
|
+
step = [angle_of_travel(src_hsx[0], dest_hsx[0]), dest_hsx[1]-src_hsx[1], dest_hsx[2]-src_hsx[2] ].map { |v| v/step_count }
|
91
|
+
|
92
|
+
# origin (self, optional)
|
93
|
+
( include_begin ? [self.dup] : [] ) +
|
94
|
+
# ...plus intermediate colors
|
95
|
+
(1..step_count-1).map { |c| RGB.send(type, zip_add(src_hsx, step.map { |v| v*c })) } +
|
96
|
+
# ...plus destination color
|
97
|
+
[another.dup]
|
98
|
+
|
99
|
+
end
|
100
|
+
|
65
101
|
end
|
data/lib/redgreenblue/ostwald.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class RGB::Color
|
2
2
|
|
3
|
-
# Returns a new RGB::Color
|
3
|
+
# Returns a new RGB::Color with this color's Ostwald full-color,
|
4
4
|
# or nil for achromatic colors (white, greys, and black).
|
5
5
|
#
|
6
6
|
# The resulting color contains no white or black,
|
data/lib/redgreenblue/random.rb
CHANGED
data/lib/redgreenblue/rgb565.rb
CHANGED
data/lib/redgreenblue/version.rb
CHANGED
data/lib/redgreenblue/web.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
class RGB::Color
|
2
2
|
|
3
|
-
#----------------------------------------------------------------------#
|
4
|
-
# Instance Methods #
|
5
|
-
#----------------------------------------------------------------------#
|
6
|
-
|
7
3
|
# Returns the object's RGB value in hexadecimal notation as used in CSS.
|
8
4
|
#
|
9
5
|
# Shortens to 3 digits when possible.
|
@@ -62,9 +58,6 @@ class RGB::Color
|
|
62
58
|
|
63
59
|
end
|
64
60
|
|
65
|
-
#----------------------------------------------------------------------#
|
66
|
-
# Module Methods #
|
67
|
-
#----------------------------------------------------------------------#
|
68
61
|
|
69
62
|
module RGB
|
70
63
|
|
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.18.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: 2022-
|
11
|
+
date: 2022-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|