chroma 0.0.1.alpha.2 → 0.0.1.alpha.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/CHANGELOG.md +34 -1
- data/README.md +3 -1
- data/Rakefile +8 -1
- data/lib/chroma.rb +60 -1
- data/lib/chroma/color.rb +50 -1
- data/lib/chroma/color/attributes.rb +31 -0
- data/lib/chroma/color/modifiers.rb +59 -1
- data/lib/chroma/color/serializers.rb +69 -0
- data/lib/chroma/color_modes.rb +36 -9
- data/lib/chroma/converters/base.rb +10 -0
- data/lib/chroma/converters/hsl_converter.rb +7 -0
- data/lib/chroma/converters/hsv_converter.rb +7 -0
- data/lib/chroma/converters/rgb_converter.rb +7 -0
- data/lib/chroma/errors.rb +6 -0
- data/lib/chroma/extensions/string.rb +11 -0
- data/lib/chroma/harmonies.rb +100 -17
- data/lib/chroma/helpers/bounders.rb +19 -1
- data/lib/chroma/palette_builder.rb +14 -0
- data/lib/chroma/rgb_generator.rb +8 -6
- data/lib/chroma/rgb_generator/base.rb +2 -0
- data/lib/chroma/rgb_generator/from_hex_string_values.rb +29 -0
- data/lib/chroma/rgb_generator/from_hsl.rb +4 -0
- data/lib/chroma/rgb_generator/from_hsl_values.rb +7 -0
- data/lib/chroma/rgb_generator/from_hsv.rb +4 -0
- data/lib/chroma/rgb_generator/from_hsv_values.rb +7 -0
- data/lib/chroma/rgb_generator/from_rgb.rb +5 -1
- data/lib/chroma/rgb_generator/from_rgb_values.rb +8 -1
- data/lib/chroma/rgb_generator/from_string.rb +12 -1
- data/lib/chroma/version.rb +1 -1
- data/spec/chroma/define_palette_spec.rb +6 -0
- data/spec/color/palette_spec.rb +173 -0
- data/spec/custom_matchers.rb +13 -0
- data/spec/spec_helper.rb +1 -7
- metadata +8 -2
@@ -1,11 +1,18 @@
|
|
1
1
|
module Chroma
|
2
2
|
module RgbGenerator
|
3
3
|
class FromHexStringValues < Base
|
4
|
+
# @param format [Symbol] color format
|
5
|
+
# @param r [String] red value
|
6
|
+
# @param g [String] green value
|
7
|
+
# @param b [String] blue value
|
8
|
+
# @param a [String] alpha value
|
4
9
|
def initialize(format, r, g, b, a = 'ff')
|
5
10
|
@format = format || :hex
|
6
11
|
@r, @g, @b, @a = r, g, b, a
|
7
12
|
end
|
8
13
|
|
14
|
+
# Generates a {ColorModes::Rgb}.
|
15
|
+
# @return [ColorModes::Rgb]
|
9
16
|
def generate
|
10
17
|
r, g, b = [@r, @g, @b].map { |n| n.to_i(16) }
|
11
18
|
a = @a.to_i(16) / 255.0
|
@@ -13,14 +20,36 @@ module Chroma
|
|
13
20
|
end
|
14
21
|
|
15
22
|
class << self
|
23
|
+
# Generates a {ColorModes::Rgb} from 3-character hexadecimal.
|
24
|
+
# @return [ColorModes::Rgb]
|
25
|
+
#
|
26
|
+
# @param format [Symbol] color format
|
27
|
+
# @param r [String] red value
|
28
|
+
# @param g [String] green value
|
29
|
+
# @param b [String] blue value
|
16
30
|
def from_hex3(format, r, g, b)
|
17
31
|
new(format || :hex3, r * 2, g * 2, b * 2)
|
18
32
|
end
|
19
33
|
|
34
|
+
# Generates a {ColorModes::Rgb} from 6-character hexadecimal.
|
35
|
+
# @return [ColorModes::Rgb]
|
36
|
+
#
|
37
|
+
# @param format [Symbol] color format
|
38
|
+
# @param r [String] red value
|
39
|
+
# @param g [String] green value
|
40
|
+
# @param b [String] blue value
|
20
41
|
def from_hex6(format, r, g, b)
|
21
42
|
new(format, r, g, b)
|
22
43
|
end
|
23
44
|
|
45
|
+
# Generates a {ColorModes::Rgb} from 8-character hexadecimal.
|
46
|
+
# @return [ColorModes::Rgb]
|
47
|
+
#
|
48
|
+
# @param format [Symbol] color format
|
49
|
+
# @param r [String] red value
|
50
|
+
# @param g [String] green value
|
51
|
+
# @param b [String] blue value
|
52
|
+
# @param a [String] alpha value
|
24
53
|
def from_hex8(format, a, r, g, b)
|
25
54
|
new(format || :hex8, r, g, b, a)
|
26
55
|
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
module Chroma
|
2
2
|
module RgbGenerator
|
3
3
|
class FromHsl < Base
|
4
|
+
# @param format [Symbol] color format
|
5
|
+
# @param hsl [ColorModes::Hsl]
|
4
6
|
def initialize(format, hsl)
|
5
7
|
@format = format
|
6
8
|
@hsl = hsl
|
7
9
|
end
|
8
10
|
|
11
|
+
# Generates a {ColorModes::Rgb}.
|
12
|
+
# @return [ColorModes::Rgb]
|
9
13
|
def generate
|
10
14
|
FromHslValues.new(@format, *@hsl.to_a).generate
|
11
15
|
end
|
@@ -1,6 +1,11 @@
|
|
1
1
|
module Chroma
|
2
2
|
module RgbGenerator
|
3
3
|
class FromHslValues < Base
|
4
|
+
# @param format [Symbol] color format
|
5
|
+
# @param h [String, Numeric] hue value
|
6
|
+
# @param s [String, Numeric] saturation value
|
7
|
+
# @param l [String, Numeric] lightness value
|
8
|
+
# @param a [String, Numeric] alpha value
|
4
9
|
def initialize(format, h, s, l, a = 1)
|
5
10
|
s = to_percentage(s)
|
6
11
|
l = to_percentage(l)
|
@@ -9,6 +14,8 @@ module Chroma
|
|
9
14
|
@hsl = ColorModes::Hsl.new(h, s, l, a)
|
10
15
|
end
|
11
16
|
|
17
|
+
# Generates a {ColorModes::Rgb}.
|
18
|
+
# @return [ColorModes::Rgb]
|
12
19
|
def generate
|
13
20
|
[Converters::RgbConverter.convert_hsl(@hsl), @format]
|
14
21
|
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
module Chroma
|
2
2
|
module RgbGenerator
|
3
3
|
class FromHsv < Base
|
4
|
+
# @param format [Symbol] color format
|
5
|
+
# @param hsv [ColorModes::Hsv]
|
4
6
|
def initialize(format, hsv)
|
5
7
|
@format = format
|
6
8
|
@hsv = hsv
|
7
9
|
end
|
8
10
|
|
11
|
+
# Generates a {ColorModes::Rgb}.
|
12
|
+
# @return [ColorModes::Rgb]
|
9
13
|
def generate
|
10
14
|
FromHsvValues.new(@format, *@hsv.to_a).generate
|
11
15
|
end
|
@@ -1,6 +1,11 @@
|
|
1
1
|
module Chroma
|
2
2
|
module RgbGenerator
|
3
3
|
class FromHsvValues < Base
|
4
|
+
# @param format [Symbol] color format
|
5
|
+
# @param h [String, Numeric] hue value
|
6
|
+
# @param s [String, Numeric] saturation value
|
7
|
+
# @param v [String, Numeric] value value
|
8
|
+
# @param a [String, Numeric] alpha value
|
4
9
|
def initialize(format, h, s, v, a = 1)
|
5
10
|
s = to_percentage(s)
|
6
11
|
v = to_percentage(v)
|
@@ -9,6 +14,8 @@ module Chroma
|
|
9
14
|
@hsv = ColorModes::Hsv.new(h, s, v, a)
|
10
15
|
end
|
11
16
|
|
17
|
+
# Generates a {ColorModes::Rgb}.
|
18
|
+
# @return [ColorModes::Rgb]
|
12
19
|
def generate
|
13
20
|
[Converters::RgbConverter.convert_hsv(@hsv), @format]
|
14
21
|
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
module Chroma
|
2
2
|
module RgbGenerator
|
3
3
|
class FromRgb < Base
|
4
|
+
# @param format [Symbol] color format
|
5
|
+
# @param rgb [ColorModes::Rgb]
|
4
6
|
def initialize(format, rgb)
|
5
|
-
@format = format
|
7
|
+
@format = format
|
6
8
|
@rgb = rgb
|
7
9
|
end
|
8
10
|
|
11
|
+
# Generates a {ColorModes::Rgb}.
|
12
|
+
# @return [ColorModes::Rgb]
|
9
13
|
def generate
|
10
14
|
FromRgbValues.new(@format, @rgb.r, @rgb.g, @rgb.b, @rgb.a).generate
|
11
15
|
end
|
@@ -1,11 +1,18 @@
|
|
1
1
|
module Chroma
|
2
2
|
module RgbGenerator
|
3
3
|
class FromRgbValues < Base
|
4
|
+
# @param format [Symbol] color format
|
5
|
+
# @param r [String, Numeric] red value
|
6
|
+
# @param g [String, Numeric] green value
|
7
|
+
# @param b [String, Numeric] blue value
|
8
|
+
# @param a [String, Numeric] alpha value
|
4
9
|
def initialize(format, r, g, b, a = 1)
|
5
|
-
@format = format
|
10
|
+
@format = format || :rgb
|
6
11
|
@r, @g, @b, @a = r, g, b, a
|
7
12
|
end
|
8
13
|
|
14
|
+
# Generates a {ColorModes::Rgb}.
|
15
|
+
# @return [ColorModes::Rgb]
|
9
16
|
def generate
|
10
17
|
r, g, b = [@r, @g, @b].map { |n| bound01(n, 255) * 255 }
|
11
18
|
a = bound_alpha(@a)
|
@@ -1,6 +1,11 @@
|
|
1
1
|
module Chroma
|
2
2
|
module RgbGenerator
|
3
3
|
class FromString < Base
|
4
|
+
# Returns the regex matchers and rgb generation classes for various
|
5
|
+
# string color formats.
|
6
|
+
#
|
7
|
+
# @api private
|
8
|
+
# @return [Hash<Symbol, Hash>]
|
4
9
|
def self.matchers
|
5
10
|
@matchers ||= begin
|
6
11
|
# TinyColor.js matchers
|
@@ -28,10 +33,14 @@ module Chroma
|
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
36
|
+
# @param format [Symbol] unused
|
37
|
+
# @param input [String] input to parse
|
31
38
|
def initialize(format, input)
|
32
39
|
@input = normalize_input(input)
|
33
40
|
end
|
34
41
|
|
42
|
+
# Generates a {ColorModes::Rgb}.
|
43
|
+
# @return [ColorModes::Rgb]
|
35
44
|
def generate
|
36
45
|
get_generator.generate
|
37
46
|
end
|
@@ -52,7 +61,9 @@ module Chroma
|
|
52
61
|
!(match = h[:regex].match(color)).nil?
|
53
62
|
end
|
54
63
|
|
55
|
-
|
64
|
+
if match.nil?
|
65
|
+
raise Errors::UnrecognizedColor, "Unrecognized color `#{color}'"
|
66
|
+
end
|
56
67
|
|
57
68
|
build_generator(match[1..-1], hash[:class_name], hash[:builder], format)
|
58
69
|
end
|
data/lib/chroma/version.rb
CHANGED
@@ -30,4 +30,10 @@ describe Chroma, '.define_palette' do
|
|
30
30
|
expect(red.palette.foo).
|
31
31
|
to generate_palette %w(#ff0000 #ffff00 #00ffff #ffff33 #808080)
|
32
32
|
end
|
33
|
+
|
34
|
+
it 'keeps the same format' do
|
35
|
+
add_palette
|
36
|
+
|
37
|
+
expect('red'.paint.palette.foo).to all have_format :name
|
38
|
+
end
|
33
39
|
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
describe Chroma::Color, '#palette' do
|
2
|
+
let(:red) { 'red'.paint }
|
3
|
+
|
4
|
+
def palette(name, *args)
|
5
|
+
red.palette.send(name, *args)
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'returns an instance of Harmonies' do
|
9
|
+
expect(red.palette).to be_a Chroma::Harmonies
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#complement' do
|
13
|
+
it 'returns the color and its complement' do
|
14
|
+
expect(red.palette.complement).to generate_palette %w(red cyan)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'keeps the same format' do
|
18
|
+
expect(red.palette.complement).to all have_format :name
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with option :as' do
|
22
|
+
it 'outputs the palette as an array of the string format' do
|
23
|
+
expect(red.palette.complement(as: :hex)).
|
24
|
+
to eq %w(#ff0000 #00ffff)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#triad' do
|
30
|
+
it 'returns the triad palette' do
|
31
|
+
expect(red.palette.triad).to generate_palette %w(red lime blue)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'keeps the same format' do
|
35
|
+
expect(red.palette.triad).to all have_format :name
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'with option :as' do
|
39
|
+
it 'outputs the palette as an array of the string format' do
|
40
|
+
expect(red.palette.triad(as: :hex)).
|
41
|
+
to eq %w(#ff0000 #00ff00 #0000ff)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#tetrad' do
|
47
|
+
it 'returns the tetrad palette' do
|
48
|
+
expect(red.palette.tetrad).to generate_palette %w(red #80ff00 cyan #7f00ff)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'keeps the same format' do
|
52
|
+
expect(red.palette.tetrad).to all have_format :name
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'with option :as' do
|
56
|
+
it 'outputs the palette as an array of the string format' do
|
57
|
+
expect(red.palette.tetrad(as: :hex)).
|
58
|
+
to eq %w(#ff0000 #80ff00 #00ffff #7f00ff)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#split_complement' do
|
64
|
+
it 'returns the split complement palette' do
|
65
|
+
expect(red.palette.split_complement).to generate_palette %w(red #cf0 #06f)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'keeps the same format' do
|
69
|
+
expect(red.palette.split_complement).to all have_format :name
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'with option :as' do
|
73
|
+
it 'outputs the palette as an array of the string format' do
|
74
|
+
expect(red.palette.split_complement(as: :hex)).
|
75
|
+
to eq %w(#ff0000 #ccff00 #0066ff)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#analogous' do
|
81
|
+
context 'with default parameters' do
|
82
|
+
it 'returns the analogous palette' do
|
83
|
+
expect(red.palette.analogous).
|
84
|
+
to generate_palette %w(#f00 #f06 #f03 #f00 #f30 #f60)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'keeps the same format' do
|
88
|
+
expect(red.palette.analogous).to all have_format :name
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'with option :as' do
|
92
|
+
it 'outputs the palette as an array of the string format' do
|
93
|
+
expect(red.palette.analogous(as: :hex)).
|
94
|
+
to eq %w(#ff0000 #ff0066 #ff0033 #ff0000 #ff3300 #ff6600)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'with `results` argument' do
|
100
|
+
it 'returns the analogous palette' do
|
101
|
+
expect(red.palette.analogous(results: 3)).
|
102
|
+
to generate_palette %w(#f00 #ff001a #ff1a00)
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'keeps the same format' do
|
106
|
+
expect(red.palette.analogous(results: 3)).to all have_format :name
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'with option :as' do
|
110
|
+
it 'outputs the palette as an array of the string format' do
|
111
|
+
expect(red.palette.analogous(results: 3, as: :hex)).
|
112
|
+
to eq %w(#ff0000 #ff001a #ff1a00)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'with `results` and `slices` arguments' do
|
118
|
+
it 'returns the analogous palette' do
|
119
|
+
expect(red.palette.analogous(results: 3, slices: 10)).
|
120
|
+
to generate_palette %w(#f00 #ff004c #ff4d00)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'keeps the same format' do
|
124
|
+
expect(red.palette.analogous(results: 3, slices: 10)).to all have_format :name
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'with option :as' do
|
128
|
+
it 'outputs the palette as an array of the string format' do
|
129
|
+
expect(red.palette.analogous(results: 3, slices: 10, as: :hex)).
|
130
|
+
to eq %w(#ff0000 #ff004c #ff4d00)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '#monochromatic' do
|
137
|
+
context 'with default parameters' do
|
138
|
+
it 'returns the monochromatic palette' do
|
139
|
+
expect(red.palette.monochromatic).
|
140
|
+
to generate_palette %w(#f00 #2a0000 #500 #800000 #a00 #d40000)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'keeps the same format' do
|
144
|
+
expect(red.palette.monochromatic).to all have_format :name
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'with option :as' do
|
148
|
+
it 'outputs the palette as an array of the string format' do
|
149
|
+
expect(red.palette.monochromatic(as: :hex)).
|
150
|
+
to eq %w(#ff0000 #2a0000 #550000 #800000 #aa0000 #d40000)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'with `results` argument' do
|
156
|
+
it 'returns the monochromatic palette' do
|
157
|
+
expect(red.palette.monochromatic(results: 3)).
|
158
|
+
to generate_palette %w(#f00 #500 #a00)
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'keeps the same format' do
|
162
|
+
expect(red.palette.monochromatic(results: 3)).to all have_format :name
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'with option :as' do
|
166
|
+
it 'outputs the palette as an array of the string format' do
|
167
|
+
expect(red.palette.monochromatic(results: 3, as: :hex)).
|
168
|
+
to eq %w(#ff0000 #550000 #aa0000)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chroma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.alpha.
|
4
|
+
version: 0.0.1.alpha.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Fairbank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -61,6 +61,7 @@ extra_rdoc_files: []
|
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
63
|
- ".rspec"
|
64
|
+
- ".yardopts"
|
64
65
|
- CHANGELOG.md
|
65
66
|
- Gemfile
|
66
67
|
- LICENSE
|
@@ -77,6 +78,7 @@ files:
|
|
77
78
|
- lib/chroma/converters/hsl_converter.rb
|
78
79
|
- lib/chroma/converters/hsv_converter.rb
|
79
80
|
- lib/chroma/converters/rgb_converter.rb
|
81
|
+
- lib/chroma/errors.rb
|
80
82
|
- lib/chroma/extensions/string.rb
|
81
83
|
- lib/chroma/harmonies.rb
|
82
84
|
- lib/chroma/helpers/bounders.rb
|
@@ -96,8 +98,10 @@ files:
|
|
96
98
|
- spec/chroma/define_palette_spec.rb
|
97
99
|
- spec/chroma/paint_spec.rb
|
98
100
|
- spec/color/modifiers_spec.rb
|
101
|
+
- spec/color/palette_spec.rb
|
99
102
|
- spec/color/serializers_spec.rb
|
100
103
|
- spec/color_spec.rb
|
104
|
+
- spec/custom_matchers.rb
|
101
105
|
- spec/spec_helper.rb
|
102
106
|
homepage: https://github.com/jfairbank/chroma
|
103
107
|
licenses:
|
@@ -127,6 +131,8 @@ test_files:
|
|
127
131
|
- spec/chroma/define_palette_spec.rb
|
128
132
|
- spec/chroma/paint_spec.rb
|
129
133
|
- spec/color/modifiers_spec.rb
|
134
|
+
- spec/color/palette_spec.rb
|
130
135
|
- spec/color/serializers_spec.rb
|
131
136
|
- spec/color_spec.rb
|
137
|
+
- spec/custom_matchers.rb
|
132
138
|
- spec/spec_helper.rb
|