color 1.4.1 → 1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.autotest +5 -0
- data/.coveralls.yml +2 -0
- data/.gemtest +0 -0
- data/.hoerc +2 -0
- data/.minitest.rb +2 -0
- data/.travis.yml +41 -0
- data/Code-of-Conduct.rdoc +41 -0
- data/Contributing.rdoc +62 -0
- data/Gemfile +9 -0
- data/History.rdoc +194 -0
- data/{Licence.txt → Licence.rdoc} +4 -4
- data/Manifest.txt +15 -7
- data/README.rdoc +52 -0
- data/Rakefile +62 -103
- data/lib/color.rb +108 -68
- data/lib/color/cmyk.rb +41 -57
- data/lib/color/css.rb +1 -22
- data/lib/color/grayscale.rb +37 -52
- data/lib/color/hsl.rb +97 -78
- data/lib/color/palette.rb +0 -12
- data/lib/color/palette/adobecolor.rb +0 -12
- data/lib/color/palette/gimp.rb +0 -12
- data/lib/color/palette/monocontrast.rb +26 -42
- data/lib/color/rgb.rb +376 -113
- data/lib/color/rgb/colors.rb +167 -0
- data/lib/color/rgb/contrast.rb +57 -0
- data/lib/color/rgb/metallic.rb +25 -40
- data/lib/color/yiq.rb +13 -35
- data/test/minitest_helper.rb +6 -0
- data/test/test_adobecolor.rb +9 -23
- data/test/test_cmyk.rb +21 -36
- data/test/test_color.rb +10 -17
- data/test/test_css.rb +12 -22
- data/test/test_gimp.rb +8 -22
- data/test/test_grayscale.rb +12 -27
- data/test/test_hsl.rb +23 -39
- data/test/test_monocontrast.rb +13 -25
- data/test/test_rgb.rb +98 -35
- data/test/test_yiq.rb +12 -24
- metadata +279 -124
- data.tar.gz.sig +0 -3
- data/History.txt +0 -93
- data/Install.txt +0 -18
- data/README.txt +0 -32
- data/lib/color/rgb-colors.rb +0 -355
- data/setup.rb +0 -1585
- data/test/test_all.rb +0 -23
- metadata.gz.sig +0 -3
@@ -0,0 +1,167 @@
|
|
1
|
+
class Color::RGB
|
2
|
+
class << self
|
3
|
+
private
|
4
|
+
def named(rgb, *names)
|
5
|
+
__named_color(self, new(*rgb), *names)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
named [0xf0, 0xf8, 0xff], :AliceBlue
|
10
|
+
named [0xfa, 0xeb, 0xd7], :AntiqueWhite
|
11
|
+
named [0x00, 0xff, 0xff], :Aqua
|
12
|
+
named [0x7f, 0xff, 0xd4], :Aquamarine
|
13
|
+
named [0xf0, 0xff, 0xff], :Azure
|
14
|
+
named [0xf5, 0xf5, 0xdc], :Beige
|
15
|
+
named [0xff, 0xe4, 0xc4], :Bisque
|
16
|
+
named [0x66, 0x33, 0x99], :RebeccaPurple, :BeccaPurple
|
17
|
+
named [0x00, 0x00, 0x00], :Black
|
18
|
+
named [0xff, 0xeb, 0xcd], :BlanchedAlmond
|
19
|
+
named [0x00, 0x00, 0xff], :Blue
|
20
|
+
named [0x8a, 0x2b, 0xe2], :BlueViolet
|
21
|
+
named [0xa5, 0x2a, 0x2a], :Brown
|
22
|
+
named [0xde, 0xb8, 0x87], :BurlyWood, :Burlywood
|
23
|
+
named [0x5f, 0x9e, 0xa0], :CadetBlue
|
24
|
+
named [0xff, 0x5e, 0xd0], :Carnation
|
25
|
+
named [0x8d, 0x00, 0x00], :Cayenne
|
26
|
+
named [0x7f, 0xff, 0x00], :Chartreuse
|
27
|
+
named [0xd2, 0x69, 0x1e], :Chocolate
|
28
|
+
named [0xff, 0x7f, 0x50], :Coral
|
29
|
+
named [0x64, 0x95, 0xed], :CornflowerBlue
|
30
|
+
named [0xff, 0xf8, 0xdc], :Cornsilk
|
31
|
+
named [0xdc, 0x14, 0x3c], :Crimson
|
32
|
+
named [0x00, 0xff, 0xff], :Cyan
|
33
|
+
named [0x00, 0x00, 0x8b], :DarkBlue
|
34
|
+
named [0x00, 0x8b, 0x8b], :DarkCyan
|
35
|
+
named [0xb8, 0x86, 0x0b], :DarkGoldenRod, :DarkGoldenrod
|
36
|
+
named [0xa9, 0xa9, 0xa9], :DarkGray, :DarkGrey
|
37
|
+
named [0x00, 0x64, 0x00], :DarkGreen
|
38
|
+
named [0xbd, 0xb7, 0x6b], :DarkKhaki
|
39
|
+
named [0x8b, 0x00, 0x8b], :DarkMagenta
|
40
|
+
named [0x55, 0x6b, 0x2f], :DarkOliveGreen, :DarkoliveGreen
|
41
|
+
named [0xff, 0x8c, 0x00], :DarkOrange
|
42
|
+
named [0x99, 0x32, 0xcc], :DarkOrchid
|
43
|
+
named [0x8b, 0x00, 0x00], :DarkRed
|
44
|
+
named [0xe9, 0x96, 0x7a], :DarkSalmon, :Darksalmon
|
45
|
+
named [0x8f, 0xbc, 0x8f], :DarkSeaGreen
|
46
|
+
named [0x48, 0x3d, 0x8b], :DarkSlateBlue
|
47
|
+
named [0x2f, 0x4f, 0x4f], :DarkSlateGray, :DarkSlateGrey
|
48
|
+
named [0x00, 0xce, 0xd1], :DarkTurquoise
|
49
|
+
named [0x94, 0x00, 0xd3], :DarkViolet
|
50
|
+
named [0xff, 0x8c, 0x00], :Darkorange
|
51
|
+
named [0xff, 0x14, 0x93], :DeepPink
|
52
|
+
named [0x00, 0xbf, 0xbf], :DeepSkyBlue
|
53
|
+
named [0x69, 0x69, 0x69], :DimGray, :DimGrey
|
54
|
+
named [0x1e, 0x90, 0xff], :DodgerBlue
|
55
|
+
named [0xd1, 0x92, 0x75], :Feldspar
|
56
|
+
named [0xb2, 0x22, 0x22], :FireBrick, :Firebrick
|
57
|
+
named [0xff, 0xfa, 0xf0], :FloralWhite
|
58
|
+
named [0x22, 0x8b, 0x22], :ForestGreen
|
59
|
+
named [0xff, 0x00, 0xff], :Fuchsia
|
60
|
+
named [0xdc, 0xdc, 0xdc], :Gainsboro
|
61
|
+
named [0xf8, 0xf8, 0xff], :GhostWhite
|
62
|
+
named [0xff, 0xd7, 0x00], :Gold
|
63
|
+
named [0xda, 0xa5, 0x20], :GoldenRod, :Goldenrod
|
64
|
+
named [0x80, 0x80, 0x80], :Gray, :Grey
|
65
|
+
named [10, 10, 10, 100.0], :Gray10, :Grey10
|
66
|
+
named [20, 20, 20, 100.0], :Gray20, :Grey20
|
67
|
+
named [30, 30, 30, 100.0], :Gray30, :Grey30
|
68
|
+
named [40, 40, 40, 100.0], :Gray40, :Grey40
|
69
|
+
named [50, 50, 50, 100.0], :Gray50, :Grey50
|
70
|
+
named [60, 60, 60, 100.0], :Gray60, :Grey60
|
71
|
+
named [70, 70, 70, 100.0], :Gray70, :Grey70
|
72
|
+
named [80, 80, 80, 100.0], :Gray80, :Grey80
|
73
|
+
named [90, 90, 90, 100.0], :Gray90, :Grey90
|
74
|
+
named [0x00, 0x80, 0x00], :Green
|
75
|
+
named [0xad, 0xff, 0x2f], :GreenYellow
|
76
|
+
named [0xf0, 0xff, 0xf0], :HoneyDew, :Honeydew
|
77
|
+
named [0xff, 0x69, 0xb4], :HotPink
|
78
|
+
named [0xcd, 0x5c, 0x5c], :IndianRed
|
79
|
+
named [0x4b, 0x00, 0x82], :Indigo
|
80
|
+
named [0xff, 0xff, 0xf0], :Ivory
|
81
|
+
named [0xf0, 0xe6, 0x8c], :Khaki
|
82
|
+
named [0xe6, 0xe6, 0xfa], :Lavender
|
83
|
+
named [0xff, 0xf0, 0xf5], :LavenderBlush
|
84
|
+
named [0x7c, 0xfc, 0x00], :LawnGreen
|
85
|
+
named [0xff, 0xfa, 0xcd], :LemonChiffon
|
86
|
+
named [0xad, 0xd8, 0xe6], :LightBlue
|
87
|
+
named [0xf0, 0x80, 0x80], :LightCoral
|
88
|
+
named [0xe0, 0xff, 0xff], :LightCyan
|
89
|
+
named [0xfa, 0xfa, 0xd2], :LightGoldenRodYellow, :LightGoldenrodYellow
|
90
|
+
named [0xd3, 0xd3, 0xd3], :LightGray, :LightGrey
|
91
|
+
named [0x90, 0xee, 0x90], :LightGreen
|
92
|
+
named [0xff, 0xb6, 0xc1], :LightPink
|
93
|
+
named [0xff, 0xa0, 0x7a], :LightSalmon, :Lightsalmon
|
94
|
+
named [0x20, 0xb2, 0xaa], :LightSeaGreen
|
95
|
+
named [0x87, 0xce, 0xfa], :LightSkyBlue
|
96
|
+
named [0x84, 0x70, 0xff], :LightSlateBlue
|
97
|
+
named [0x77, 0x88, 0x99], :LightSlateGray, :LightSlateGrey
|
98
|
+
named [0xb0, 0xc4, 0xde], :LightSteelBlue, :LightsteelBlue
|
99
|
+
named [0xff, 0xff, 0xe0], :LightYellow
|
100
|
+
named [0x00, 0xff, 0x00], :Lime
|
101
|
+
named [0x32, 0xcd, 0x32], :LimeGreen
|
102
|
+
named [0xfa, 0xf0, 0xe6], :Linen
|
103
|
+
named [0xff, 0x00, 0xff], :Magenta
|
104
|
+
named [0x80, 0x00, 0x00], :Maroon
|
105
|
+
named [0x66, 0xcd, 0xaa], :MediumAquaMarine, :MediumAquamarine
|
106
|
+
named [0x00, 0x00, 0xcd], :MediumBlue
|
107
|
+
named [0xba, 0x55, 0xd3], :MediumOrchid
|
108
|
+
named [0x93, 0x70, 0xdb], :MediumPurple
|
109
|
+
named [0x3c, 0xb3, 0x71], :MediumSeaGreen
|
110
|
+
named [0x7b, 0x68, 0xee], :MediumSlateBlue
|
111
|
+
named [0x00, 0xfa, 0x9a], :MediumSpringGreen
|
112
|
+
named [0x48, 0xd1, 0xcc], :MediumTurquoise
|
113
|
+
named [0xc7, 0x15, 0x85], :MediumVioletRed
|
114
|
+
named [0x19, 0x19, 0x70], :MidnightBlue
|
115
|
+
named [0xf5, 0xff, 0xfa], :MintCream
|
116
|
+
named [0xff, 0xe4, 0xe1], :MistyRose
|
117
|
+
named [0xff, 0xe4, 0xb5], :Moccasin
|
118
|
+
named [0xff, 0xde, 0xad], :NavajoWhite
|
119
|
+
named [0x00, 0x00, 0x80], :Navy
|
120
|
+
named [0xfd, 0xf5, 0xe6], :OldLace
|
121
|
+
named [0x80, 0x80, 0x00], :Olive
|
122
|
+
named [0x6b, 0x8e, 0x23], :OliveDrab, :Olivedrab
|
123
|
+
named [0xff, 0xa5, 0x00], :Orange
|
124
|
+
named [0xff, 0x45, 0x00], :OrangeRed
|
125
|
+
named [0xda, 0x70, 0xd6], :Orchid
|
126
|
+
named [0xee, 0xe8, 0xaa], :PaleGoldenRod, :PaleGoldenrod
|
127
|
+
named [0x98, 0xfb, 0x98], :PaleGreen
|
128
|
+
named [0xaf, 0xee, 0xee], :PaleTurquoise
|
129
|
+
named [0xdb, 0x70, 0x93], :PaleVioletRed
|
130
|
+
named [0xff, 0xef, 0xd5], :PapayaWhip
|
131
|
+
named [0xff, 0xda, 0xb9], :PeachPuff, :Peachpuff
|
132
|
+
named [0xcd, 0x85, 0x3f], :Peru
|
133
|
+
named [0xff, 0xc0, 0xcb], :Pink
|
134
|
+
named [0xdd, 0xa0, 0xdd], :Plum
|
135
|
+
named [0xb0, 0xe0, 0xe6], :PowderBlue
|
136
|
+
named [0x80, 0x00, 0x80], :Purple
|
137
|
+
named [0xff, 0x00, 0x00], :Red
|
138
|
+
named [0xbc, 0x8f, 0x8f], :RosyBrown
|
139
|
+
named [0x41, 0x69, 0xe1], :RoyalBlue
|
140
|
+
named [0x8b, 0x45, 0x13], :SaddleBrown
|
141
|
+
named [0xfa, 0x80, 0x72], :Salmon
|
142
|
+
named [0xf4, 0xa4, 0x60], :SandyBrown
|
143
|
+
named [0x2e, 0x8b, 0x57], :SeaGreen
|
144
|
+
named [0xff, 0xf5, 0xee], :SeaShell, :Seashell
|
145
|
+
named [0xa0, 0x52, 0x2d], :Sienna
|
146
|
+
named [0xc0, 0xc0, 0xc0], :Silver
|
147
|
+
named [0x87, 0xce, 0xeb], :SkyBlue
|
148
|
+
named [0x6a, 0x5a, 0xcd], :SlateBlue
|
149
|
+
named [0x70, 0x80, 0x90], :SlateGray, :SlateGrey
|
150
|
+
named [0xff, 0xfa, 0xfa], :Snow
|
151
|
+
named [0x00, 0xff, 0x7f], :SpringGreen
|
152
|
+
named [0x46, 0x82, 0xb4], :SteelBlue
|
153
|
+
named [0xd2, 0xb4, 0x8c], :Tan
|
154
|
+
named [0x00, 0x80, 0x80], :Teal
|
155
|
+
named [0xd8, 0xbf, 0xd8], :Thistle
|
156
|
+
named [0xff, 0x63, 0x47], :Tomato
|
157
|
+
named [0x40, 0xe0, 0xd0], :Turquoise
|
158
|
+
named [0xee, 0x82, 0xee], :Violet
|
159
|
+
named [0xd0, 0x20, 0x90], :VioletRed
|
160
|
+
named [0xf5, 0xde, 0xb3], :Wheat
|
161
|
+
named [0xff, 0xff, 0xff], :White
|
162
|
+
named [0xf5, 0xf5, 0xf5], :WhiteSmoke
|
163
|
+
named [0xff, 0xff, 0x00], :Yellow
|
164
|
+
named [0x9a, 0xcd, 0x32], :YellowGreen
|
165
|
+
end
|
166
|
+
|
167
|
+
require 'color/rgb/metallic'
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
|
3
|
+
class Color::RGB
|
4
|
+
# Outputs how much contrast this color has with another RGB color.
|
5
|
+
# Computes the same regardless of which one is considered foreground. If
|
6
|
+
# the other color does not have a #to_rgb method, this will throw an
|
7
|
+
# exception. Anything over about 0.22 should have a high likelihood of
|
8
|
+
# being legible, but the larger the difference, the more contrast.
|
9
|
+
# Otherwise, to be safe go with something > 0.3
|
10
|
+
def contrast(other)
|
11
|
+
other = coerce(other)
|
12
|
+
|
13
|
+
# The following numbers have been set with some care.
|
14
|
+
((diff_brightness(other) * 0.65) +
|
15
|
+
(diff_hue(other) * 0.20) +
|
16
|
+
(diff_luminosity(other) * 0.15))
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
# Provides the luminosity difference between two rbg vals
|
21
|
+
def diff_luminosity(other)
|
22
|
+
other = coerce(other)
|
23
|
+
l1 = (0.2126 * (other.r) ** 2.2) +
|
24
|
+
(0.7152 * (other.b) ** 2.2) +
|
25
|
+
(0.0722 * (other.g) ** 2.2);
|
26
|
+
|
27
|
+
l2 = (0.2126 * (self.r) ** 2.2) +
|
28
|
+
(0.7152 * (self.b) ** 2.2) +
|
29
|
+
(0.0722 * (self.g) ** 2.2);
|
30
|
+
|
31
|
+
((([l1, l2].max) + 0.05) / ( ([l1, l2].min) + 0.05 ) - 1) / 20.0
|
32
|
+
end
|
33
|
+
|
34
|
+
# Provides the brightness difference.
|
35
|
+
def diff_brightness(other)
|
36
|
+
other = other.to_rgb
|
37
|
+
br1 = (299 * other.r + 587 * other.g + 114 * other.b)
|
38
|
+
br2 = (299 * self.r + 587 * self.g + 114 * self.b)
|
39
|
+
(br1 - br2).abs / 1000.0;
|
40
|
+
end
|
41
|
+
|
42
|
+
# Provides the euclidean distance between the two color values
|
43
|
+
def diff_euclidean(other)
|
44
|
+
other = other.to_rgb
|
45
|
+
((((other.r - self.r) ** 2) +
|
46
|
+
((other.g - self.g) ** 2) +
|
47
|
+
((other.b - self.b) ** 2)) ** 0.5) / 1.7320508075688772
|
48
|
+
end
|
49
|
+
|
50
|
+
# Difference in the two colors' hue
|
51
|
+
def diff_hue(other)
|
52
|
+
other = other.to_rgb
|
53
|
+
((self.r - other.r).abs +
|
54
|
+
(self.g - other.g).abs +
|
55
|
+
(self.b - other.b).abs) / 3
|
56
|
+
end
|
57
|
+
end
|
data/lib/color/rgb/metallic.rb
CHANGED
@@ -1,43 +1,28 @@
|
|
1
|
-
|
2
|
-
# Color
|
3
|
-
# Colour management with Ruby
|
4
|
-
# http://rubyforge.org/projects/color
|
5
|
-
# Version 1.4.1
|
6
|
-
#
|
7
|
-
# Licensed under a MIT-style licence. See Licence.txt in the main
|
8
|
-
# distribution for full licensing information.
|
9
|
-
#
|
10
|
-
# Copyright (c) 2005 - 2010 Austin Ziegler and Matt Lyon
|
11
|
-
#++
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
12
2
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
Copper = Color::RGB.new(0xb8, 0x73, 0x33)
|
18
|
-
Iron = Color::RGB.new(0x4c, 0x4c, 0x4c)
|
19
|
-
Lead = Color::RGB.new(0x19, 0x19, 0x19)
|
20
|
-
Magnesium = Color::RGB.new(0xb3, 0xb3, 0xb3)
|
21
|
-
Mercury = Color::RGB.new(0xe6, 0xe6, 0xe6)
|
22
|
-
Nickel = Color::RGB.new(0x80, 0x80, 0x80)
|
23
|
-
PolySilicon = Color::RGB.new(0x60, 0x00, 0x00)
|
24
|
-
Poly = PolySilicon
|
25
|
-
Silver = Color::RGB.new(0xcc, 0xcc, 0xcc)
|
26
|
-
Steel = Color::RGB.new(0x66, 0x66, 0x66)
|
27
|
-
Tin = Color::RGB.new(0x7f, 0x7f, 0x7f)
|
28
|
-
Tungsten = Color::RGB.new(0x33, 0x33, 0x33)
|
3
|
+
class Color::RGB
|
4
|
+
# This namespace contains some RGB metallic colours suggested by Jim
|
5
|
+
# Freeze.
|
6
|
+
module Metallic; end
|
29
7
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
8
|
+
class << self
|
9
|
+
private
|
10
|
+
def metallic(rgb, *names)
|
11
|
+
__named_color(Metallic, new(*rgb), *names)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
metallic [0x99, 0x99, 0x99], :Aluminum
|
16
|
+
metallic [0xd9, 0x87, 0x19], :CoolCopper
|
17
|
+
metallic [0xb8, 0x73, 0x33], :Copper
|
18
|
+
metallic [0x4c, 0x4c, 0x4c], :Iron
|
19
|
+
metallic [0x19, 0x19, 0x19], :Lead
|
20
|
+
metallic [0xb3, 0xb3, 0xb3], :Magnesium
|
21
|
+
metallic [0xe6, 0xe6, 0xe6], :Mercury
|
22
|
+
metallic [0x80, 0x80, 0x80], :Nickel
|
23
|
+
metallic [0x60, 0x00, 0x00], :PolySilicon, :Poly
|
24
|
+
metallic [0xcc, 0xcc, 0xcc], :Silver
|
25
|
+
metallic [0x66, 0x66, 0x66], :Steel
|
26
|
+
metallic [0x7f, 0x7f, 0x7f], :Tin
|
27
|
+
metallic [0x33, 0x33, 0x33], :Tungsten
|
43
28
|
end
|
data/lib/color/yiq.rb
CHANGED
@@ -1,50 +1,24 @@
|
|
1
|
-
#--
|
2
|
-
# Color
|
3
|
-
# Colour management with Ruby
|
4
|
-
# http://rubyforge.org/projects/color
|
5
|
-
# Version 1.4.1
|
6
|
-
#
|
7
|
-
# Licensed under a MIT-style licence. See Licence.txt in the main
|
8
|
-
# distribution for full licensing information.
|
9
|
-
#
|
10
|
-
# Copyright (c) 2005 - 2010 Austin Ziegler and Matt Lyon
|
11
|
-
#++
|
12
|
-
|
13
1
|
# A colour object representing YIQ (NTSC) colour encoding.
|
14
2
|
class Color::YIQ
|
3
|
+
include Color
|
4
|
+
|
15
5
|
# Creates a YIQ colour object from fractional values 0 .. 1.
|
16
6
|
#
|
17
7
|
# Color::YIQ.new(0.3, 0.2, 0.1)
|
18
|
-
def self.from_fraction(y = 0, i = 0, q = 0)
|
19
|
-
|
20
|
-
color.y = y
|
21
|
-
color.i = i
|
22
|
-
color.q = q
|
23
|
-
color
|
8
|
+
def self.from_fraction(y = 0, i = 0, q = 0, &block)
|
9
|
+
new(y, i, q, 1.0, &block)
|
24
10
|
end
|
25
11
|
|
26
12
|
# Creates a YIQ colour object from percentages 0 .. 100.
|
27
13
|
#
|
28
14
|
# Color::YIQ.new(10, 20, 30)
|
29
|
-
def initialize(y = 0, i = 0, q = 0)
|
30
|
-
@y = y /
|
31
|
-
|
32
|
-
@q = q / 100.0
|
15
|
+
def initialize(y = 0, i = 0, q = 0, radix = 100.0, &block) # :yields self:
|
16
|
+
@y, @i, @q = [ y, i, q ].map { |v| Color.normalize(v / radix) }
|
17
|
+
block.call if block
|
33
18
|
end
|
34
19
|
|
35
|
-
|
36
|
-
|
37
|
-
# colour and a non-YIQ colour will be approximate and based on the other
|
38
|
-
# colour's #to_yiq conversion. If there is no #to_yiq conversion, this
|
39
|
-
# will raise an exception. This will report that two YIQ values are
|
40
|
-
# equivalent if all component colours are within COLOR_TOLERANCE of each
|
41
|
-
# other.
|
42
|
-
def ==(other)
|
43
|
-
other = other.to_yiq
|
44
|
-
other.kind_of?(Color::YIQ) and
|
45
|
-
((@y - other.y).abs <= Color::COLOR_TOLERANCE) and
|
46
|
-
((@i - other.i).abs <= Color::COLOR_TOLERANCE) and
|
47
|
-
((@q - other.q).abs <= Color::COLOR_TOLERANCE)
|
20
|
+
def coerce(other)
|
21
|
+
other.to_yiq
|
48
22
|
end
|
49
23
|
|
50
24
|
def to_yiq
|
@@ -81,4 +55,8 @@ class Color::YIQ
|
|
81
55
|
def inspect
|
82
56
|
"YIQ [%.2f%%, %.2f%%, %.2f%%]" % [ @y * 100, @i * 100, @q * 100 ]
|
83
57
|
end
|
58
|
+
|
59
|
+
def to_a
|
60
|
+
[ y, i, q ]
|
61
|
+
end
|
84
62
|
end
|
data/test/test_adobecolor.rb
CHANGED
@@ -1,24 +1,12 @@
|
|
1
|
-
|
2
|
-
#--
|
3
|
-
# Color
|
4
|
-
# Colour management with Ruby
|
5
|
-
# http://rubyforge.org/projects/color
|
6
|
-
# Version 1.5.0
|
7
|
-
#
|
8
|
-
# Licensed under a MIT-style licence. See Licence.txt in the main
|
9
|
-
# distribution for full licensing information.
|
10
|
-
#
|
11
|
-
# Copyright (c) 2005 - 2010 Austin Ziegler and Matt Lyon
|
12
|
-
#++
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
13
2
|
|
14
|
-
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
|
15
|
-
require 'test/unit'
|
16
3
|
require 'color'
|
17
4
|
require 'color/palette/adobecolor'
|
5
|
+
require 'minitest_helper'
|
18
6
|
|
19
7
|
module TestColor
|
20
8
|
module TestPalette
|
21
|
-
class TestAdobeColor < Test
|
9
|
+
class TestAdobeColor < Minitest::Test
|
22
10
|
include Color::Palette
|
23
11
|
|
24
12
|
# This is based on the Visibone Anglo-Centric Color Code List; this is
|
@@ -335,7 +323,7 @@ QwBNAFkASwAAAA0JxA2sEZQF3AAAAAsAVQBOAEsATgBPAFcATgAgADEAMwAA
|
|
335
323
|
|
336
324
|
def test_version1
|
337
325
|
v1 = VISIBONE_V1.unpack("m*")[0]
|
338
|
-
|
326
|
+
@aco = AdobeColor.new(v1)
|
339
327
|
assert_equal(216, @aco.size)
|
340
328
|
assert_equal(1, @aco.version)
|
341
329
|
assert_equal({:rgb => 216}, @aco.statistics)
|
@@ -378,12 +366,10 @@ QwBNAFkASwAAAA0JxA2sEZQF3AAAAAsAVQBOAEsATgBPAFcATgAgADEAMwAA
|
|
378
366
|
end
|
379
367
|
|
380
368
|
def test_exercise
|
381
|
-
|
382
|
-
|
383
|
-
f.write EXERCISE.unpack("m*")[0]
|
384
|
-
end
|
369
|
+
File.open(@filename, "wb") do |f|
|
370
|
+
f.write EXERCISE.unpack("m*")[0]
|
385
371
|
end
|
386
|
-
|
372
|
+
@aco = AdobeColor.from_file(@filename)
|
387
373
|
assert_equal(5, @aco.size)
|
388
374
|
assert_equal(7, @aco.instance_variable_get(:@order).size)
|
389
375
|
end
|
@@ -396,7 +382,7 @@ QwBNAFkASwAAAA0JxA2sEZQF3AAAAAsAVQBOAEsATgBPAFcATgAgADEAMwAA
|
|
396
382
|
|
397
383
|
def test_each_name
|
398
384
|
v2 = VISIBONE_V2.unpack("m*")[0]
|
399
|
-
|
385
|
+
@aco = AdobeColor.new(v2)
|
400
386
|
assert_equal(216, @aco.size)
|
401
387
|
assert_equal(2, @aco.version)
|
402
388
|
@aco.each_name do |n, s|
|
@@ -408,7 +394,7 @@ QwBNAFkASwAAAA0JxA2sEZQF3AAAAAsAVQBOAEsATgBPAFcATgAgADEAMwAA
|
|
408
394
|
|
409
395
|
def test_values_at
|
410
396
|
v2 = VISIBONE_V2.unpack("m*")[0]
|
411
|
-
|
397
|
+
@aco = AdobeColor.new(v2)
|
412
398
|
assert_equal(216, @aco.size)
|
413
399
|
assert_equal(2, @aco.version)
|
414
400
|
assert_equal([Color::RGB::White, Color::RGB.from_html("#ff0033")],
|
data/test/test_cmyk.rb
CHANGED
@@ -1,22 +1,10 @@
|
|
1
|
-
|
2
|
-
#--
|
3
|
-
# Color
|
4
|
-
# Colour management with Ruby
|
5
|
-
# http://rubyforge.org/projects/color
|
6
|
-
# Version 1.5.0
|
7
|
-
#
|
8
|
-
# Licensed under a MIT-style licence. See Licence.txt in the main
|
9
|
-
# distribution for full licensing information.
|
10
|
-
#
|
11
|
-
# Copyright (c) 2005 - 2010 Austin Ziegler and Matt Lyon
|
12
|
-
#++
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
13
2
|
|
14
|
-
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
|
15
|
-
require 'test/unit'
|
16
3
|
require 'color'
|
4
|
+
require 'minitest_helper'
|
17
5
|
|
18
6
|
module TestColor
|
19
|
-
class TestCMYK < Test
|
7
|
+
class TestCMYK < Minitest::Test
|
20
8
|
def setup
|
21
9
|
@cmyk = Color::CMYK.new(10, 20, 30, 40)
|
22
10
|
end
|
@@ -24,44 +12,44 @@ module TestColor
|
|
24
12
|
def test_cyan
|
25
13
|
assert_in_delta(0.1, @cmyk.c, Color::COLOR_TOLERANCE)
|
26
14
|
assert_in_delta(10, @cmyk.cyan, Color::COLOR_TOLERANCE)
|
27
|
-
|
15
|
+
@cmyk.cyan = 20
|
28
16
|
assert_in_delta(0.2, @cmyk.c, Color::COLOR_TOLERANCE)
|
29
|
-
|
17
|
+
@cmyk.c = 2.0
|
30
18
|
assert_in_delta(100, @cmyk.cyan, Color::COLOR_TOLERANCE)
|
31
|
-
|
19
|
+
@cmyk.c = -1.0
|
32
20
|
assert_in_delta(0.0, @cmyk.c, Color::COLOR_TOLERANCE)
|
33
21
|
end
|
34
22
|
|
35
23
|
def test_magenta
|
36
24
|
assert_in_delta(0.2, @cmyk.m, Color::COLOR_TOLERANCE)
|
37
25
|
assert_in_delta(20, @cmyk.magenta, Color::COLOR_TOLERANCE)
|
38
|
-
|
26
|
+
@cmyk.magenta = 30
|
39
27
|
assert_in_delta(0.3, @cmyk.m, Color::COLOR_TOLERANCE)
|
40
|
-
|
28
|
+
@cmyk.m = 2.0
|
41
29
|
assert_in_delta(100, @cmyk.magenta, Color::COLOR_TOLERANCE)
|
42
|
-
|
30
|
+
@cmyk.m = -1.0
|
43
31
|
assert_in_delta(0.0, @cmyk.m, Color::COLOR_TOLERANCE)
|
44
32
|
end
|
45
33
|
|
46
34
|
def test_yellow
|
47
35
|
assert_in_delta(0.3, @cmyk.y, Color::COLOR_TOLERANCE)
|
48
36
|
assert_in_delta(30, @cmyk.yellow, Color::COLOR_TOLERANCE)
|
49
|
-
|
37
|
+
@cmyk.yellow = 20
|
50
38
|
assert_in_delta(0.2, @cmyk.y, Color::COLOR_TOLERANCE)
|
51
|
-
|
39
|
+
@cmyk.y = 2.0
|
52
40
|
assert_in_delta(100, @cmyk.yellow, Color::COLOR_TOLERANCE)
|
53
|
-
|
41
|
+
@cmyk.y = -1.0
|
54
42
|
assert_in_delta(0.0, @cmyk.y, Color::COLOR_TOLERANCE)
|
55
43
|
end
|
56
44
|
|
57
45
|
def test_black
|
58
46
|
assert_in_delta(0.4, @cmyk.k, Color::COLOR_TOLERANCE)
|
59
47
|
assert_in_delta(40, @cmyk.black, Color::COLOR_TOLERANCE)
|
60
|
-
|
48
|
+
@cmyk.black = 20
|
61
49
|
assert_in_delta(0.2, @cmyk.k, Color::COLOR_TOLERANCE)
|
62
|
-
|
50
|
+
@cmyk.k = 2.0
|
63
51
|
assert_in_delta(100, @cmyk.black, Color::COLOR_TOLERANCE)
|
64
|
-
|
52
|
+
@cmyk.k = -1.0
|
65
53
|
assert_in_delta(0.0, @cmyk.k, Color::COLOR_TOLERANCE)
|
66
54
|
end
|
67
55
|
|
@@ -75,16 +63,14 @@ module TestColor
|
|
75
63
|
end
|
76
64
|
|
77
65
|
def test_to_grayscale
|
78
|
-
gs =
|
79
|
-
assert_nothing_raised { gs = @cmyk.to_grayscale }
|
66
|
+
gs = @cmyk.to_grayscale
|
80
67
|
assert_kind_of(Color::GrayScale, gs)
|
81
68
|
assert_in_delta(0.4185, gs.g, Color::COLOR_TOLERANCE)
|
82
69
|
assert_kind_of(Color::GreyScale, @cmyk.to_greyscale)
|
83
70
|
end
|
84
71
|
|
85
72
|
def test_to_hsl
|
86
|
-
hsl =
|
87
|
-
assert_nothing_raised { hsl = @cmyk.to_hsl }
|
73
|
+
hsl = @cmyk.to_hsl
|
88
74
|
assert_kind_of(Color::HSL, hsl)
|
89
75
|
assert_in_delta(0.48, hsl.l, Color::COLOR_TOLERANCE)
|
90
76
|
assert_in_delta(0.125, hsl.s, Color::COLOR_TOLERANCE)
|
@@ -94,14 +80,13 @@ module TestColor
|
|
94
80
|
end
|
95
81
|
|
96
82
|
def test_to_rgb
|
97
|
-
rgb =
|
98
|
-
assert_nothing_raised { rgb = @cmyk.to_rgb(true) }
|
83
|
+
rgb = @cmyk.to_rgb(true)
|
99
84
|
assert_kind_of(Color::RGB, rgb)
|
100
85
|
assert_in_delta(0.5, rgb.r, Color::COLOR_TOLERANCE)
|
101
86
|
assert_in_delta(0.4, rgb.g, Color::COLOR_TOLERANCE)
|
102
87
|
assert_in_delta(0.3, rgb.b, Color::COLOR_TOLERANCE)
|
103
88
|
|
104
|
-
|
89
|
+
rgb = @cmyk.to_rgb
|
105
90
|
assert_kind_of(Color::RGB, rgb)
|
106
91
|
assert_in_delta(0.54, rgb.r, Color::COLOR_TOLERANCE)
|
107
92
|
assert_in_delta(0.48, rgb.g, Color::COLOR_TOLERANCE)
|
@@ -110,6 +95,7 @@ module TestColor
|
|
110
95
|
assert_equal("#8a7a6b", @cmyk.html)
|
111
96
|
assert_equal("rgb(54.00%, 48.00%, 42.00%)", @cmyk.css_rgb)
|
112
97
|
assert_equal("rgba(54.00%, 48.00%, 42.00%, 1.00)", @cmyk.css_rgba)
|
98
|
+
assert_equal("rgba(54.00%, 48.00%, 42.00%, 0.20)", @cmyk.css_rgba(0.2))
|
113
99
|
end
|
114
100
|
|
115
101
|
def test_inspect
|
@@ -117,8 +103,7 @@ module TestColor
|
|
117
103
|
end
|
118
104
|
|
119
105
|
def test_to_yiq
|
120
|
-
yiq =
|
121
|
-
assert_nothing_raised { yiq = @cmyk.to_yiq }
|
106
|
+
yiq = @cmyk.to_yiq
|
122
107
|
assert_kind_of(Color::YIQ, yiq)
|
123
108
|
assert_in_delta(0.4911, yiq.y, Color::COLOR_TOLERANCE)
|
124
109
|
assert_in_delta(0.05502, yiq.i, Color::COLOR_TOLERANCE)
|