paleta 0.2.2 → 0.2.3
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/paleta/color.rb +3 -3
- data/lib/paleta/palette.rb +8 -8
- data/lib/paleta/version.rb +1 -1
- data/readme.markdown +7 -8
- data/spec/models/color_spec.rb +3 -3
- data/spec/models/palette_spec.rb +34 -35
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbc68d095b1685f151b262ce76ec4c5f51380b07
|
4
|
+
data.tar.gz: c31c9b06f8045aa81bd4aca725c83411f1c75f55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3affa703081598c705dc1b678ac3f8d2dc1b47a363338dd86e7778d0df9b8fcd2ba8d53434f2a7a24130214aab65cf0c83abcb9b4dbdddcc94e2bb26c387d371
|
7
|
+
data.tar.gz: 707274da81a1aeec5ee96bff51feadd472867791f73aaaffc9619e2b8abb15c569d9e1a6c0b926cb2f0cf9567a9ad7067686b5848a83319b585ff6d355221a3a
|
data/lib/paleta/color.rb
CHANGED
@@ -277,10 +277,10 @@ module Paleta
|
|
277
277
|
end
|
278
278
|
end
|
279
279
|
|
280
|
-
@hue = h * 60
|
280
|
+
@hue = (h * 60.0).round(8)
|
281
281
|
@hue += 360 if @hue < 0
|
282
|
-
@saturation = s * 100
|
283
|
-
@lightness = l * 100
|
282
|
+
@saturation = (s * 100.0).round(8)
|
283
|
+
@lightness = (l * 100.0).round(8)
|
284
284
|
end
|
285
285
|
|
286
286
|
def update_rgb
|
data/lib/paleta/palette.rb
CHANGED
@@ -227,6 +227,14 @@ module Paleta
|
|
227
227
|
array
|
228
228
|
end
|
229
229
|
|
230
|
+
def fit
|
231
|
+
# create a 3xn matrix where n = @colors.size to represent the set of colors
|
232
|
+
reds = @colors.map { |c| c.red }
|
233
|
+
greens = @colors.map { |c| c.green }
|
234
|
+
blues = @colors.map { |c| c.blue }
|
235
|
+
multiple_regression(reds, greens, blues)
|
236
|
+
end
|
237
|
+
|
230
238
|
private
|
231
239
|
|
232
240
|
def self.generate_analogous_from_color(color, size)
|
@@ -345,13 +353,5 @@ module Paleta
|
|
345
353
|
end
|
346
354
|
palette.sort! { |a, b| a.saturation <=> b.saturation }
|
347
355
|
end
|
348
|
-
|
349
|
-
def fit
|
350
|
-
# create a 3xn matrix where n = @colors.size to represent the set of colors
|
351
|
-
reds = @colors.map { |c| c.red }
|
352
|
-
greens = @colors.map { |c| c.green }
|
353
|
-
blues = @colors.map { |c| c.blue }
|
354
|
-
multiple_regression(reds, greens, blues)
|
355
|
-
end
|
356
356
|
end
|
357
357
|
end
|
data/lib/paleta/version.rb
CHANGED
data/readme.markdown
CHANGED
@@ -174,49 +174,49 @@ Palettes can be generated from a "seed" Color or from an image by using the `gen
|
|
174
174
|
|
175
175
|
```ruby
|
176
176
|
color = Paleta::Color.new(:hex, "ff0000")
|
177
|
-
palette = Paleta::Palette.generate(:type => :shades, :from => :color, :size => 5)
|
177
|
+
palette = Paleta::Palette.generate(:type => :shades, :from => :color, :size => 5, :color => color)
|
178
178
|
```
|
179
179
|
|
180
180
|
**Generate a Palette of analogous Colors from a Color**
|
181
181
|
|
182
182
|
```ruby
|
183
183
|
color = Paleta::Color.new(:hex, "0066cc")
|
184
|
-
palette = Paleta::Palette.generate(:type => :analogous, :from => :color, :size => 5)
|
184
|
+
palette = Paleta::Palette.generate(:type => :analogous, :from => :color, :size => 5, :color => color)
|
185
185
|
```
|
186
186
|
|
187
187
|
**Generate a Palette of monochromatic Colors from a Color**
|
188
188
|
|
189
189
|
```ruby
|
190
190
|
color = Paleta::Color.new(:hex, "336699")
|
191
|
-
palette = Paleta::Palette.generate(:type => :monochromatic, :from => :color, :size => 5)
|
191
|
+
palette = Paleta::Palette.generate(:type => :monochromatic, :from => :color, :size => 5, :color => color)
|
192
192
|
```
|
193
193
|
|
194
194
|
**Generate a Palette of complementary Colors from a Color**
|
195
195
|
|
196
196
|
```ruby
|
197
197
|
color = Paleta::Color.new(:hex, "0000ff")
|
198
|
-
palette = Paleta::Palette.generate(:type => :complementary, :from => :color, :size => 5)
|
198
|
+
palette = Paleta::Palette.generate(:type => :complementary, :from => :color, :size => 5, :color => color)
|
199
199
|
```
|
200
200
|
|
201
201
|
**Generate a Palette of split-complement Colors from a Color**
|
202
202
|
|
203
203
|
```ruby
|
204
204
|
color = Paleta::Color.new(:hex, "006699")
|
205
|
-
palette = Paleta::Palette.generate(:type => :split_complement, :from => :color, :size => 5)
|
205
|
+
palette = Paleta::Palette.generate(:type => :split_complement, :from => :color, :size => 5, :color => color)
|
206
206
|
```
|
207
207
|
|
208
208
|
**Generate a Palette of triad Colors from a Color**
|
209
209
|
|
210
210
|
```ruby
|
211
211
|
color = Paleta::Color.new(:hex, "006699")
|
212
|
-
palette = Paleta::Palette.generate(:type => :triad, :from => :color, :size => 5)
|
212
|
+
palette = Paleta::Palette.generate(:type => :triad, :from => :color, :size => 5, :color => color)
|
213
213
|
```
|
214
214
|
|
215
215
|
**Generate a Palette of tetrad Colors from a Color**
|
216
216
|
|
217
217
|
```ruby
|
218
218
|
color = Paleta::Color.new(:hex, "dd5533")
|
219
|
-
palette = Paleta::Palette.generate(:type => :tetrad, :from => :color, :size => 5)
|
219
|
+
palette = Paleta::Palette.generate(:type => :tetrad, :from => :color, :size => 5, :color => color)
|
220
220
|
```
|
221
221
|
|
222
222
|
**Generate a random Palette**
|
@@ -237,4 +237,3 @@ palette = Paleta::Palette.generate(:from => :image, :image => "/path/to/image.jp
|
|
237
237
|
|
238
238
|
See the [documentation](http://rubydoc.info/gems/paleta/ "Documentation").
|
239
239
|
|
240
|
-
|
data/spec/models/color_spec.rb
CHANGED
@@ -81,11 +81,11 @@ describe Paleta::Color do
|
|
81
81
|
it "should determine its equality to another Color" do
|
82
82
|
color1 = Paleta::Color.new(237, 172, 33)
|
83
83
|
color2 = Paleta::Color.new(:hex, "EDAC21")
|
84
|
-
(color1 == color2).should
|
84
|
+
(color1 == color2).should be true
|
85
85
|
color3 = Paleta::Color.new(:hsl, 200, 50, 100)
|
86
|
-
(color1 == color3).should
|
86
|
+
(color1 == color3).should be false
|
87
87
|
obj = Object.new
|
88
|
-
(color1 == obj).should
|
88
|
+
(color1 == obj).should be false
|
89
89
|
end
|
90
90
|
|
91
91
|
it "should calculate its HSL value on itialization" do
|
data/spec/models/palette_spec.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Paleta::Palette do
|
4
|
-
|
4
|
+
|
5
5
|
it "should initialize with a set of Colors" do
|
6
6
|
c1 = Paleta::Color.new(13, 57, 182)
|
7
7
|
c2 = Paleta::Color.new(94, 161, 235)
|
8
8
|
Paleta::Palette.new(c1, c2)
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
it "should not initialize if an object in the set is not a Color" do
|
12
12
|
c1 = Paleta::Color.new(13, 57, 182)
|
13
13
|
c2 = 13
|
14
14
|
expect{ Paleta::Palette.new(c1, c2) }.to raise_error(ArgumentError)
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "should add Colors" do
|
18
18
|
c1 = Paleta::Color.new(13, 57, 182)
|
19
19
|
c2 = Paleta::Color.new(94, 161, 235)
|
20
20
|
c3 = Paleta::Color.new(0, 0, 0)
|
21
21
|
palette = Paleta::Palette.new(c1)
|
22
22
|
palette << c2 << c3
|
23
|
-
palette.include?(c2).should
|
23
|
+
palette.include?(c2).should be true
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it "should add Colors with push" do
|
27
27
|
c1 = Paleta::Color.new(13, 57, 182)
|
28
28
|
c2 = Paleta::Color.new(94, 161, 235)
|
@@ -30,31 +30,31 @@ describe Paleta::Palette do
|
|
30
30
|
palette.push(c2)
|
31
31
|
palette[1].should == c2
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
it "should remove the last Color with pop" do
|
35
35
|
c1 = Paleta::Color.new(13, 57, 182)
|
36
36
|
c2 = Paleta::Color.new(94, 161, 235)
|
37
37
|
palette = Paleta::Palette.new(c1, c2)
|
38
38
|
c = palette.pop()
|
39
39
|
c.should == c2
|
40
|
-
palette.include?(c2).should
|
40
|
+
palette.include?(c2).should be false
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
it "should remove Colors by index" do
|
44
44
|
c1 = Paleta::Color.new(13, 57, 182)
|
45
45
|
c2 = Paleta::Color.new(94, 161, 235)
|
46
46
|
palette = Paleta::Palette.new(c1, c2)
|
47
47
|
palette.delete_at(0)
|
48
|
-
palette.include?(c1).should
|
48
|
+
palette.include?(c1).should be false
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
it "should allow array-style accessing of Colors" do
|
52
52
|
c1 = Paleta::Color.new(13, 57, 182)
|
53
53
|
palette = Paleta::Palette.new(c1)
|
54
54
|
palette[0].should == c1
|
55
55
|
palette[1].should be_nil
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
it "should lighten each Color in a Palette by a percentage" do
|
59
59
|
c1 = Paleta::Color.new(13, 57, 182)
|
60
60
|
c2 = Paleta::Color.new(94, 161, 235)
|
@@ -66,7 +66,7 @@ describe Paleta::Palette do
|
|
66
66
|
palette[0].lightness.should == lightness1 + percent
|
67
67
|
palette[1].lightness.should == lightness2 + percent
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
it "should darken each Color in a Palette by a percentage" do
|
71
71
|
c1 = Paleta::Color.new(13, 57, 182)
|
72
72
|
c2 = Paleta::Color.new(94, 161, 235)
|
@@ -78,7 +78,7 @@ describe Paleta::Palette do
|
|
78
78
|
palette[0].lightness.should == lightness1 - percent
|
79
79
|
palette[1].lightness.should == lightness2 - percent
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
it "should invert each Color in a Palette" do
|
83
83
|
c1 = Paleta::Color.new(13, 57, 182)
|
84
84
|
c2 = Paleta::Color.new(94, 161, 235)
|
@@ -91,9 +91,8 @@ describe Paleta::Palette do
|
|
91
91
|
palette[1].green.should == 94
|
92
92
|
palette[1].blue.should == 20
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
it "should calculate a multiple regression over each Color in the Palette in RGB space" do
|
96
|
-
Paleta::Palette.send(:public, :fit)
|
97
96
|
c1 = Paleta::Color.new(13, 57, 182)
|
98
97
|
c2 = Paleta::Color.new(94, 161, 235)
|
99
98
|
c3 = Paleta::Color.new(237, 172, 33)
|
@@ -106,35 +105,35 @@ describe Paleta::Palette do
|
|
106
105
|
r[:offset][:y].round(5).should == 50.84953
|
107
106
|
r[:offset][:z].round(5).should == 130.15404
|
108
107
|
end
|
109
|
-
|
108
|
+
|
110
109
|
it "should calculate its similarity to another Palette" do
|
111
110
|
c1 = Paleta::Color.new(0, 0, 0)
|
112
111
|
p1 = Paleta::Palette.new(c1)
|
113
|
-
|
112
|
+
|
114
113
|
c2 = Paleta::Color.new(255, 255, 255)
|
115
114
|
p2 = Paleta::Palette.new(c2)
|
116
|
-
|
115
|
+
|
117
116
|
p1.similarity(p2).should == 1
|
118
|
-
|
117
|
+
|
119
118
|
c3 = Paleta::Color.new(0, 0, 0)
|
120
119
|
c4 = Paleta::Color.new(255, 255, 255)
|
121
120
|
p3 = Paleta::Palette.new(c3, c4)
|
122
|
-
|
121
|
+
|
123
122
|
c5 = Paleta::Color.new(0, 0, 0)
|
124
123
|
c6 = Paleta::Color.new(255, 255, 255)
|
125
124
|
p4 = Paleta::Palette.new(c5, c6)
|
126
125
|
p3.similarity(p4).should == 0
|
127
|
-
|
126
|
+
|
128
127
|
c7 = Paleta::Color.new(13, 57, 182)
|
129
128
|
c8 = Paleta::Color.new(237, 172, 33)
|
130
129
|
p5 = Paleta::Palette.new(c7, c8)
|
131
|
-
|
130
|
+
|
132
131
|
c9 = Paleta::Color.new(13, 57, 182)
|
133
132
|
c10 = Paleta::Color.new(94, 161, 235)
|
134
133
|
p6 = Paleta::Palette.new(c9, c10)
|
135
134
|
p5.similarity(p6).round(5).should == 0.00669
|
136
135
|
end
|
137
|
-
|
136
|
+
|
138
137
|
it "should generate a new Palette of shades of a single Color" do
|
139
138
|
color = Paleta::Color.new(:hex, "ff0000")
|
140
139
|
palette = Paleta::Palette.generate(:from => :color, :color => color, :size => 5)
|
@@ -149,7 +148,7 @@ describe Paleta::Palette do
|
|
149
148
|
palette[3].lightness.should == 70
|
150
149
|
palette[4].lightness.should == 90
|
151
150
|
end
|
152
|
-
|
151
|
+
|
153
152
|
it "should generate a new Palette of Colors analogous to the seed Color" do
|
154
153
|
color = Paleta::Color.new(:hex, "0066cc")
|
155
154
|
palette = Paleta::Palette.generate(:type => :analogous, :from => :color, :color => color, :size => 5)
|
@@ -164,7 +163,7 @@ describe Paleta::Palette do
|
|
164
163
|
palette[3].hue.should == 230
|
165
164
|
palette[4].hue.should == 250
|
166
165
|
end
|
167
|
-
|
166
|
+
|
168
167
|
it "should generate a new Palette of Colors monochromatic to the seed Color" do
|
169
168
|
color = Paleta::Color.new(:hex, "0066cc")
|
170
169
|
palette = Paleta::Palette.generate(:type => :monochromatic, :from => :color, :color => color, :size => 5)
|
@@ -179,19 +178,19 @@ describe Paleta::Palette do
|
|
179
178
|
palette[3].saturation.should == 80
|
180
179
|
palette[4].saturation.should == 100
|
181
180
|
end
|
182
|
-
|
181
|
+
|
183
182
|
it "should generate a new Palette of random Colors" do
|
184
183
|
palette = Paleta::Palette.generate(:type => :random, :size => 5)
|
185
184
|
palette.size.should == 5
|
186
185
|
end
|
187
|
-
|
186
|
+
|
188
187
|
it "should generate a new complementary Palette from the seed Color" do
|
189
188
|
color = Paleta::Color.new(:hex, "0066cc")
|
190
189
|
palette = Paleta::Palette.generate(:type => :complementary, :from => :color, :color => color, :size => 5)
|
191
190
|
palette.size.should == 5
|
192
191
|
palette.each do |c|
|
193
192
|
c.lightness.should == color.lightness
|
194
|
-
[color.hue, color.complement.hue].include?(c.hue).should
|
193
|
+
[color.hue, color.complement.hue].include?(c.hue).should be true
|
195
194
|
end
|
196
195
|
end
|
197
196
|
|
@@ -201,7 +200,7 @@ describe Paleta::Palette do
|
|
201
200
|
palette.size.should == 5
|
202
201
|
palette.each do |c|
|
203
202
|
c.lightness.should == color.lightness
|
204
|
-
[color.hue, (color.hue + 120) % 360, (color.hue + 240) % 360].include?(c.hue).should
|
203
|
+
[color.hue, (color.hue + 120) % 360, (color.hue + 240) % 360].include?(c.hue).should be true
|
205
204
|
end
|
206
205
|
end
|
207
206
|
|
@@ -211,31 +210,31 @@ describe Paleta::Palette do
|
|
211
210
|
palette.size.should == 5
|
212
211
|
palette.each do |c|
|
213
212
|
c.lightness.should == color.lightness
|
214
|
-
[color.hue, (color.hue + 90) % 360, (color.hue + 180) % 360, (color.hue + 270) % 360].include?(c.hue).should
|
213
|
+
[color.hue, (color.hue + 90) % 360, (color.hue + 180) % 360, (color.hue + 270) % 360].include?(c.hue).should be true
|
215
214
|
end
|
216
215
|
end
|
217
|
-
|
216
|
+
|
218
217
|
it "should generate a new split-complement Palette from the seed Color" do
|
219
218
|
color = Paleta::Color.new(:hex, "0066cc")
|
220
219
|
palette = Paleta::Palette.generate(:type => :split_complement, :from => :color, :color => color, :size => 5)
|
221
220
|
palette.size.should == 5
|
222
221
|
palette.each do |c|
|
223
222
|
c.lightness.should == color.lightness
|
224
|
-
[color.hue, (color.hue + 150) % 360, (color.hue + 210) % 360].include?(c.hue).should
|
223
|
+
[color.hue, (color.hue + 150) % 360, (color.hue + 210) % 360].include?(c.hue).should be true
|
225
224
|
end
|
226
225
|
end
|
227
|
-
|
226
|
+
|
228
227
|
it "should generate a Palette from an image" do
|
229
228
|
path = File.join(File.dirname(__FILE__), '..', 'images/test.jpg')
|
230
229
|
size = 5
|
231
230
|
palette = Paleta::Palette.generate(:from => :image, :image => path, :size => size)
|
232
231
|
palette.size.should == size
|
233
232
|
end
|
234
|
-
|
233
|
+
|
235
234
|
it "should raise an error when generating a Palette from an invalid image" do
|
236
235
|
expect{ Paleta::Palette.generate(:from => :image, :image => "/no/image.here") }.to raise_error(RuntimeError)
|
237
236
|
end
|
238
|
-
|
237
|
+
|
239
238
|
it "should return an array of colors, where each color is represented as an array of component values" do
|
240
239
|
c1 = Paleta::Color.new(13, 57, 182)
|
241
240
|
c2 = Paleta::Color.new(94, 161, 235)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paleta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Stephens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|