paleta 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -1
- data/Gemfile +1 -0
- data/lib/paleta/color.rb +84 -25
- data/lib/paleta/palette.rb +118 -28
- data/lib/paleta/version.rb +1 -1
- data/readme.markdown +18 -12
- data/spec/images/test.jpg +0 -0
- data/spec/models/palette_spec.rb +18 -7
- metadata +5 -2
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/lib/paleta/color.rb
CHANGED
@@ -1,11 +1,40 @@
|
|
1
1
|
require 'paleta/core_ext/math'
|
2
2
|
|
3
3
|
module Paleta
|
4
|
+
# Represents a color
|
4
5
|
class Color
|
5
6
|
include Math
|
6
7
|
|
7
8
|
attr_reader :red, :green, :blue, :hue, :saturation, :lightness, :hex
|
8
9
|
|
10
|
+
# Initailize a {Color}
|
11
|
+
#
|
12
|
+
# @overload initialize()
|
13
|
+
# Initialize a {Color} to black
|
14
|
+
#
|
15
|
+
# @overload initialize(color)
|
16
|
+
# Initialize a {Color} from a {Color}
|
17
|
+
# @param [Color] color a color to copy
|
18
|
+
#
|
19
|
+
# @overload initialize(model, value)
|
20
|
+
# Initialize a {Color} with a hex value
|
21
|
+
# @param [Symbol] model the color model, should be :hex in this case
|
22
|
+
# @param [String] value a 6 character hexadecimal string
|
23
|
+
#
|
24
|
+
# @overload initialize(model, value, value, value)
|
25
|
+
# Initialize a {Color} with HSL or RGB component values
|
26
|
+
# @param [Symbol] model the color model, should be :hsl or :rgb
|
27
|
+
# @param [Number] (red,hue) the red or hue component value, depending on the value of model
|
28
|
+
# @param [Number] (green,saturation) the green or saturation component value
|
29
|
+
# @param [Number] (blue,lightness) the blue or lightness component value
|
30
|
+
#
|
31
|
+
# @overload initialize(value, value, value)
|
32
|
+
# Initialize a {Color} with RGB component values
|
33
|
+
# @param [Number] red the red component value
|
34
|
+
# @param [Number] green the green component value
|
35
|
+
# @param [Number] blue the blue component value
|
36
|
+
#
|
37
|
+
# @return [Color] A new instance of {Color}
|
9
38
|
def initialize(*args)
|
10
39
|
|
11
40
|
if args.length == 1 && args[0].is_a?(Color)
|
@@ -31,22 +60,6 @@ module Paleta
|
|
31
60
|
end
|
32
61
|
end
|
33
62
|
|
34
|
-
def rgb_init(red = 0, green = 0, blue = 0)
|
35
|
-
self.red = red
|
36
|
-
self.green = green
|
37
|
-
self.blue = blue
|
38
|
-
end
|
39
|
-
|
40
|
-
def hsl_init(hue = 0, saturation = 0, lightness = 0)
|
41
|
-
self.hue = hue
|
42
|
-
self.saturation = saturation
|
43
|
-
self.lightness = lightness
|
44
|
-
end
|
45
|
-
|
46
|
-
def hex_init(val = "000000")
|
47
|
-
self.hex = val
|
48
|
-
end
|
49
|
-
|
50
63
|
def red=(val)
|
51
64
|
@red = range_validator(val, 0..255)
|
52
65
|
update_hsl
|
@@ -92,44 +105,63 @@ module Paleta
|
|
92
105
|
update_hsl
|
93
106
|
end
|
94
107
|
|
108
|
+
# Determine the equality of the receiver and another {Color}
|
109
|
+
# @param [Color] color color to compare
|
110
|
+
# @return [Boolean]
|
95
111
|
def ==(color)
|
96
112
|
color.is_a?(Color) ? (self.hex == color.hex) : false
|
97
113
|
end
|
98
114
|
|
99
|
-
|
115
|
+
# Create a copy of the receiver and lighten it by a percentage
|
116
|
+
# @param [Number] percentage percentage by which to lighten the {Color}
|
117
|
+
# @return [Color] a lightened copy of the receiver
|
118
|
+
def lighten(percentage = 5)
|
100
119
|
copy = self.class.new(self)
|
101
|
-
copy.lighten!(
|
120
|
+
copy.lighten!(percentage)
|
102
121
|
copy
|
103
122
|
end
|
104
123
|
|
105
|
-
|
106
|
-
|
124
|
+
# Lighten the receiver by a percentage
|
125
|
+
# @param [Number] percentage percentage by which to lighten the {Color}
|
126
|
+
# @return [Color] self
|
127
|
+
def lighten!(percentage = 5)
|
128
|
+
@lightness += percentage
|
107
129
|
@lightness = 100 if @lightness > 100
|
108
130
|
update_rgb
|
109
131
|
update_hex
|
110
132
|
self
|
111
133
|
end
|
112
134
|
|
113
|
-
|
135
|
+
# Create a copy of the receiver and darken it by a percentage
|
136
|
+
# @param [Number] percentage percentage by which to darken the {Color}
|
137
|
+
# @return [Color] a darkened copy of the receiver
|
138
|
+
def darken(percentage = 5)
|
114
139
|
copy = self.class.new(self)
|
115
|
-
copy.darken!(
|
140
|
+
copy.darken!(percentage)
|
116
141
|
copy
|
117
142
|
end
|
118
143
|
|
119
|
-
|
120
|
-
|
144
|
+
# Darken the receiver by a percentage
|
145
|
+
# @param [Number] percentage percentage by which to darken the {Color}
|
146
|
+
# @return [Color] self
|
147
|
+
def darken!(percentage = 5)
|
148
|
+
@lightness -= percentage
|
121
149
|
@lightness = 0 if @lightness < 0
|
122
150
|
update_rgb
|
123
151
|
update_hex
|
124
152
|
self
|
125
153
|
end
|
126
154
|
|
155
|
+
# Create a copy of the receiver and invert it
|
156
|
+
# @return [Color] an inverted copy of the receiver
|
127
157
|
def invert
|
128
158
|
copy = self.class.new(self)
|
129
159
|
copy.invert!
|
130
160
|
copy
|
131
161
|
end
|
132
162
|
|
163
|
+
# Invert the receiver
|
164
|
+
# @return [Color] self
|
133
165
|
def invert!
|
134
166
|
@red = 255 - @red
|
135
167
|
@green = 255 - @green
|
@@ -139,12 +171,16 @@ module Paleta
|
|
139
171
|
self
|
140
172
|
end
|
141
173
|
|
174
|
+
# Create a copy of the receiver and desaturate it
|
175
|
+
# @return [Color] a desaturated copy of the receiver
|
142
176
|
def desaturate
|
143
177
|
copy = self.class.new(self)
|
144
178
|
copy.desaturate!
|
145
179
|
copy
|
146
180
|
end
|
147
|
-
|
181
|
+
|
182
|
+
# Desaturate the receiver
|
183
|
+
# @return [Color] self
|
148
184
|
def desaturate!
|
149
185
|
@saturation = 0
|
150
186
|
update_rgb
|
@@ -152,12 +188,16 @@ module Paleta
|
|
152
188
|
self
|
153
189
|
end
|
154
190
|
|
191
|
+
# Create a new {Color} that is the complement of the receiver
|
192
|
+
# @return [Color] a desaturated copy of the receiver
|
155
193
|
def complement
|
156
194
|
copy = self.class.new(self)
|
157
195
|
copy.complement!
|
158
196
|
copy
|
159
197
|
end
|
160
198
|
|
199
|
+
# Turn the receiver into it's complement
|
200
|
+
# @return [Color] self
|
161
201
|
def complement!
|
162
202
|
@hue = (@hue + 180) % 360
|
163
203
|
update_rgb
|
@@ -165,12 +205,31 @@ module Paleta
|
|
165
205
|
self
|
166
206
|
end
|
167
207
|
|
208
|
+
# Calculate the similarity between the receiver and another {Color}
|
209
|
+
# @param [Color] color color to calculate the similarity to
|
210
|
+
# @return [Number] a value in [0..1] with 0 being identical and 1 being as dissimilar as possible
|
168
211
|
def similarity(color)
|
169
212
|
distance({ :r => @red, :g => @green, :b => @blue}, { :r => color.red, :g => color.green, :b => color.blue}) / sqrt(3 * (255 ** 2))
|
170
213
|
end
|
171
214
|
|
172
215
|
private
|
173
216
|
|
217
|
+
def rgb_init(red = 0, green = 0, blue = 0)
|
218
|
+
self.red = red
|
219
|
+
self.green = green
|
220
|
+
self.blue = blue
|
221
|
+
end
|
222
|
+
|
223
|
+
def hsl_init(hue = 0, saturation = 0, lightness = 0)
|
224
|
+
self.hue = hue
|
225
|
+
self.saturation = saturation
|
226
|
+
self.lightness = lightness
|
227
|
+
end
|
228
|
+
|
229
|
+
def hex_init(val = "000000")
|
230
|
+
self.hex = val
|
231
|
+
end
|
232
|
+
|
174
233
|
def update_hsl
|
175
234
|
r = @red / 255.0 rescue 0.0
|
176
235
|
g = @green / 255.0 rescue 0.0
|
data/lib/paleta/palette.rb
CHANGED
@@ -1,20 +1,58 @@
|
|
1
1
|
require 'paleta/core_ext/math'
|
2
2
|
|
3
3
|
module Paleta
|
4
|
+
|
5
|
+
module MagickDependent
|
6
|
+
def self.included(klass)
|
7
|
+
require 'RMagick'
|
8
|
+
klass.extend(ClassMethods)
|
9
|
+
rescue LoadError
|
10
|
+
puts "You must install RMagick to use Palette.generate(:from => :image, ...)"
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def generate_from_image(path, size = 5)
|
15
|
+
include Magick
|
16
|
+
begin
|
17
|
+
image = Magick::ImageList.new(path)
|
18
|
+
|
19
|
+
# quantize image to the nearest power of 2 greater the desired palette size
|
20
|
+
quantized_image = image.quantize((Math.sqrt(size).ceil ** 2), Magick::RGBColorspace)
|
21
|
+
colors = quantized_image.color_histogram.sort { |a, b| b[1] <=> a[1] }[0..(size - 1)].map do |color|
|
22
|
+
Paleta::Color.new(color[0].red / 256, color[0].green / 256, color[0].blue / 256)
|
23
|
+
end
|
24
|
+
return Paleta::Palette.new(colors)
|
25
|
+
rescue Magick::ImageMagickError
|
26
|
+
raise "Invalid image at " << path
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Represents a palette, a collection of {Color}s
|
4
33
|
class Palette
|
5
34
|
include Math
|
6
35
|
include Enumerable
|
36
|
+
include MagickDependent
|
7
37
|
|
8
38
|
attr_accessor :colors
|
9
39
|
|
40
|
+
# Initialize a {Palette} from a list of {Color}s
|
41
|
+
# @param [Array] colors a list of {Color}s to include in the {Palette}
|
42
|
+
# @return [Palette] A new instance of {Palette}
|
10
43
|
def initialize(*args)
|
11
44
|
@colors = []
|
12
45
|
colors = (args.length == 1 && args[0].is_a?(Array)) ? args[0] : args
|
13
|
-
colors.each
|
14
|
-
self << color
|
15
|
-
end
|
46
|
+
colors.each { |color| self << color }
|
16
47
|
end
|
17
48
|
|
49
|
+
# Add a {Color} to the {Palette}
|
50
|
+
# @overload <<(color)
|
51
|
+
# @param [Color] color a {Color} to add to the receiver
|
52
|
+
# @overload <<(palette)
|
53
|
+
# @param [Palette] palette a {Palette} to merge with the receiver
|
54
|
+
# @return [Palette] self
|
55
|
+
# @see Paleta::Palette.push(obj)
|
18
56
|
def <<(obj)
|
19
57
|
if obj.is_a?(Color)
|
20
58
|
@colors << obj
|
@@ -26,67 +64,97 @@ module Paleta
|
|
26
64
|
self
|
27
65
|
end
|
28
66
|
|
67
|
+
# Add a {Color} to the {Palette}
|
68
|
+
# @overload push(color)
|
69
|
+
# @param [Color] color a {Color} to add to the receiver
|
70
|
+
# @overload push(palette)
|
71
|
+
# @param [Palette] palette a {Palette} to merge with the receiver
|
72
|
+
# @return [Palette] self
|
73
|
+
# @see Paleta::Palette.<<(obj)
|
29
74
|
def push(obj)
|
30
75
|
self << obj
|
31
76
|
end
|
32
77
|
|
78
|
+
# Remove the most recently added {Color} from the receiver
|
33
79
|
def pop
|
34
80
|
@colors.pop
|
35
81
|
end
|
36
82
|
|
37
|
-
|
38
|
-
|
83
|
+
# Remove a {Color} from the receiver by index
|
84
|
+
# @param [Number] index the index at which to remove a {Color}
|
85
|
+
def delete_at(index = 0)
|
86
|
+
@colors.delete_at(index)
|
39
87
|
end
|
40
88
|
|
41
|
-
|
42
|
-
|
89
|
+
# Access a {Color} in the receiver by index
|
90
|
+
# @param [Number] index the index at which to access a {Color}
|
91
|
+
def [](index)
|
92
|
+
@colors[index]
|
43
93
|
end
|
44
94
|
|
95
|
+
# The number of {Color}s in the {Palette}
|
96
|
+
# @return [Number] the number of {Color}s in the receiver
|
45
97
|
def size
|
46
98
|
@colors.size
|
47
99
|
end
|
48
100
|
|
101
|
+
# Iterate through each {Color} in the {Palette}
|
49
102
|
def each
|
50
103
|
@colors.each { |c| yield c }
|
51
104
|
end
|
52
105
|
|
53
|
-
|
54
|
-
|
106
|
+
# Create a new instance of {Palette} that is a sorted copy of the receiver
|
107
|
+
# @return [Palette] a new instance of {Palette}
|
108
|
+
def sort(&blk)
|
109
|
+
@colors.sort(&blk)
|
55
110
|
Paleta::Palette.new(@colors)
|
56
111
|
end
|
57
112
|
|
58
|
-
|
59
|
-
|
113
|
+
# Sort the {Color}s in the receiver
|
114
|
+
# return [Palette] self
|
115
|
+
def sort!(&blk)
|
116
|
+
@colors.sort!(&blk)
|
60
117
|
self
|
61
118
|
end
|
62
119
|
|
120
|
+
# Test if a {Color} exists in the receiver
|
121
|
+
# @param [Color] color color to test for inclusion in the {Palette}
|
122
|
+
# @return [Boolean]
|
63
123
|
def include?(color)
|
64
124
|
@colors.include?(color)
|
65
125
|
end
|
66
126
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
127
|
+
# Lighen each {Color} in the receiver by a percentage
|
128
|
+
# @param [Number] percentage percentage by which to lighten each {Color} in the receiver
|
129
|
+
# @return [Palette] self
|
130
|
+
def lighten!(percentage = 5)
|
131
|
+
@colors.each { |color| color.lighten!(percentage) }
|
132
|
+
self
|
71
133
|
end
|
72
134
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
135
|
+
# Lighen each {Color} in the receiver by a percentage
|
136
|
+
# @param [Number] percentage percentage by which to lighten each {Color} in the receiver
|
137
|
+
# @return [Palette] self
|
138
|
+
def darken!(percentage = 5)
|
139
|
+
@colors.each { |color| color.darken!(percentage) }
|
140
|
+
self
|
77
141
|
end
|
78
142
|
|
143
|
+
# Invert each {Color} in the receiver by a percentage
|
144
|
+
# @return [Palette] self
|
79
145
|
def invert!
|
80
|
-
@colors.each
|
81
|
-
|
82
|
-
end
|
146
|
+
@colors.each { |color| color.invert! }
|
147
|
+
self
|
83
148
|
end
|
84
149
|
|
150
|
+
# Calculate the similarity between the receiver and another {Palette}
|
151
|
+
# @param [Palette] palette palette to calculate the similarity to
|
152
|
+
# @return [Number] a value in [0..1] with 0 being identical and 1 being as dissimilar as possible
|
85
153
|
def similarity(palette)
|
86
154
|
r, a, b = [], [], []
|
87
155
|
(0..1).each { |i| a[i], b[i] = {}, {} }
|
88
156
|
|
89
|
-
# r[i] is the
|
157
|
+
# r[i] is a hash of the multiple regression of the Palette in RGB space
|
90
158
|
r[0] = fit
|
91
159
|
r[1] = palette.fit
|
92
160
|
|
@@ -105,16 +173,38 @@ module Paleta
|
|
105
173
|
d1 + d2
|
106
174
|
end
|
107
175
|
|
176
|
+
# Generate a {Palette} from a seed {Color}
|
177
|
+
# @param [Hash] opts the options with which to generate a new {Palette}
|
178
|
+
# @option opts [Symbol] :type the type of palette to generate
|
179
|
+
# @option opts [Symbol] :from how to generate the {Palette}
|
180
|
+
# @option opts [Color] :color if :from == :color, pass a {Color} object as :color
|
181
|
+
# @option opts [String] :image if :from == :image, pass the path to an image as :image
|
182
|
+
# @option opts [Number] :size the number of {Color}s to generate for the {Palette}
|
183
|
+
# @return [Palette] A new instance of {Palette}
|
108
184
|
def self.generate(opts = {})
|
109
|
-
|
110
|
-
color = opts[:from]
|
111
|
-
type = opts[:type] || :shades
|
185
|
+
|
112
186
|
size = opts[:size] || 5
|
187
|
+
|
188
|
+
if !opts[:type].nil? && opts[:type].to_sym == :random
|
189
|
+
return self.generate_random_from_color(opts[:color], size)
|
190
|
+
end
|
191
|
+
|
192
|
+
unless (opts[:from].to_sym == :color && !opts[:color].nil?) || (opts[:from].to_sym == :image && !opts[:image].nil?)
|
193
|
+
return raise(ArgumentError, 'You must pass :from and it must be either :color or :image, then you must pass :image => "/path/to/img" or :color => color')
|
194
|
+
end
|
195
|
+
|
196
|
+
if opts[:from].to_sym == :image
|
197
|
+
path = opts[:image]
|
198
|
+
return self.generate_from_image(path, size)
|
199
|
+
end
|
200
|
+
|
201
|
+
color = opts[:color]
|
202
|
+
type = opts[:type] || :shades
|
203
|
+
|
113
204
|
case type
|
114
205
|
when :analogous; self.generate_analogous_from_color(color, size)
|
115
206
|
when :complementary; self.generate_complementary_from_color(color, size)
|
116
207
|
when :monochromatic; self.generate_monochromatic_from_color(color, size)
|
117
|
-
when :random; self.generate_random_from_color(color, size)
|
118
208
|
when :shades; self.generate_shades_from_color(color, size)
|
119
209
|
when :split_complement; self.generate_split_complement_from_color(color, size)
|
120
210
|
when :tetrad; self.generate_tetrad_from_color(color, size)
|
@@ -130,7 +220,7 @@ module Paleta
|
|
130
220
|
palette = self.new(color)
|
131
221
|
step = 20
|
132
222
|
below = (size / 2)
|
133
|
-
above = (size % 2 == 0) ? (size / 2) - 1: (size / 2)
|
223
|
+
above = (size % 2 == 0) ? (size / 2) - 1 : (size / 2)
|
134
224
|
below.times do |i|
|
135
225
|
hue = color.hue - ((i + 1) * step)
|
136
226
|
hue += 360 if hue < 0
|
data/lib/paleta/version.rb
CHANGED
data/readme.markdown
CHANGED
@@ -125,46 +125,52 @@ Palettes can calculate their similarity to other Palettes by using the `similari
|
|
125
125
|
|
126
126
|
#### Generating Palettes
|
127
127
|
|
128
|
-
Palettes can be generated from a "seed" Color by using the `generate` method.
|
129
|
-
|
130
|
-
**Generate a random Palette**
|
131
|
-
|
132
|
-
palette = Paleta::Palette.generate(:type => :random, :size = 5)
|
128
|
+
Palettes can be generated from a "seed" Color or from an image by using the `generate` method.
|
133
129
|
|
134
130
|
**Generate a Palette of shades from a Color**
|
135
131
|
|
136
132
|
color = Paleta::Color.new(:hex, "ff0000")
|
137
|
-
palette = Paleta::Palette.generate(:type => :shades, :from => color, :size => 5)
|
133
|
+
palette = Paleta::Palette.generate(:type => :shades, :from => :color, :size => 5)
|
138
134
|
|
139
135
|
**Generate a Palette of analogous Colors from a Color**
|
140
136
|
|
141
137
|
color = Paleta::Color.new(:hex, "0066cc")
|
142
|
-
palette = Paleta::Palette.generate(:type => :analogous, :from => color, :size => 5)
|
138
|
+
palette = Paleta::Palette.generate(:type => :analogous, :from => :color, :size => 5)
|
143
139
|
|
144
140
|
**Generate a Palette of monochromatic Colors from a Color**
|
145
141
|
|
146
142
|
color = Paleta::Color.new(:hex, "336699")
|
147
|
-
palette = Paleta::Palette.generate(:type => :monochromatic, :from => color, :size => 5)
|
143
|
+
palette = Paleta::Palette.generate(:type => :monochromatic, :from => :color, :size => 5)
|
148
144
|
|
149
145
|
**Generate a Palette of complementary Colors from a Color**
|
150
146
|
|
151
147
|
color = Paleta::Color.new(:hex, "0000ff")
|
152
|
-
palette = Paleta::Palette.generate(:type => :complementary, :from => color, :size => 5)
|
148
|
+
palette = Paleta::Palette.generate(:type => :complementary, :from => :color, :size => 5)
|
153
149
|
|
154
150
|
**Generate a Palette of split-complement Colors from a Color**
|
155
151
|
|
156
152
|
color = Paleta::Color.new(:hex, "006699")
|
157
|
-
palette = Paleta::Palette.generate(:type => :split_complement, :from => color, :size => 5)
|
153
|
+
palette = Paleta::Palette.generate(:type => :split_complement, :from => :color, :size => 5)
|
158
154
|
|
159
155
|
**Generate a Palette of triad Colors from a Color**
|
160
156
|
|
161
157
|
color = Paleta::Color.new(:hex, "006699")
|
162
|
-
palette = Paleta::Palette.generate(:type => :triad, :from => color, :size => 5)
|
158
|
+
palette = Paleta::Palette.generate(:type => :triad, :from => :color, :size => 5)
|
163
159
|
|
164
160
|
**Generate a Palette of tetrad Colors from a Color**
|
165
161
|
|
166
162
|
color = Paleta::Color.new(:hex, "dd5533")
|
167
|
-
palette = Paleta::Palette.generate(:type => :tetrad, :from => color, :size => 5)
|
163
|
+
palette = Paleta::Palette.generate(:type => :tetrad, :from => :color, :size => 5)
|
164
|
+
|
165
|
+
**Generate a random Palette**
|
166
|
+
|
167
|
+
palette = Paleta::Palette.generate(:type => :random, :size => 5)
|
168
|
+
|
169
|
+
Palettes can also be generated from a seed image
|
170
|
+
|
171
|
+
**Generate a Palette from an image**
|
172
|
+
|
173
|
+
palette = Paleta::Palette.generate(:from => :image, :image => "/path/to/image.jpg", :size => 5)
|
168
174
|
|
169
175
|
***
|
170
176
|
|
Binary file
|
data/spec/models/palette_spec.rb
CHANGED
@@ -137,7 +137,7 @@ describe Paleta::Palette do
|
|
137
137
|
|
138
138
|
it "should generate a new Palette of shades of a single Color" do
|
139
139
|
color = Paleta::Color.new(:hex, "ff0000")
|
140
|
-
palette = Paleta::Palette.generate(:from => color, :size => 5)
|
140
|
+
palette = Paleta::Palette.generate(:from => :color, :color => color, :size => 5)
|
141
141
|
palette.size.should == 5
|
142
142
|
palette.each do |p|
|
143
143
|
p.hue.should == color.hue
|
@@ -152,7 +152,7 @@ describe Paleta::Palette do
|
|
152
152
|
|
153
153
|
it "should generate a new Palette of Colors analogous to the seed Color" do
|
154
154
|
color = Paleta::Color.new(:hex, "0066cc")
|
155
|
-
palette = Paleta::Palette.generate(:type => :analogous, :from => color, :size => 5)
|
155
|
+
palette = Paleta::Palette.generate(:type => :analogous, :from => :color, :color => color, :size => 5)
|
156
156
|
palette.size.should == 5
|
157
157
|
palette.each do |p|
|
158
158
|
p.lightness.should == color.lightness
|
@@ -167,7 +167,7 @@ describe Paleta::Palette do
|
|
167
167
|
|
168
168
|
it "should generate a new Palette of Colors monochromatic to the seed Color" do
|
169
169
|
color = Paleta::Color.new(:hex, "0066cc")
|
170
|
-
palette = Paleta::Palette.generate(:type => :monochromatic, :from => color, :size => 5)
|
170
|
+
palette = Paleta::Palette.generate(:type => :monochromatic, :from => :color, :color => color, :size => 5)
|
171
171
|
palette.size.should == 5
|
172
172
|
palette.each do |p|
|
173
173
|
p.hue.should == color.hue
|
@@ -187,7 +187,7 @@ describe Paleta::Palette do
|
|
187
187
|
|
188
188
|
it "should generate a new complementary Palette from the seed Color" do
|
189
189
|
color = Paleta::Color.new(:hex, "0066cc")
|
190
|
-
palette = Paleta::Palette.generate(:type => :complementary, :from => color, :size => 5)
|
190
|
+
palette = Paleta::Palette.generate(:type => :complementary, :from => :color, :color => color, :size => 5)
|
191
191
|
palette.size.should == 5
|
192
192
|
palette.each do |c|
|
193
193
|
c.lightness.should == color.lightness
|
@@ -197,7 +197,7 @@ describe Paleta::Palette do
|
|
197
197
|
|
198
198
|
it "should generate a new triad Palette from the seed Color" do
|
199
199
|
color = Paleta::Color.new(:hex, "0066cc")
|
200
|
-
palette = Paleta::Palette.generate(:type => :triad, :from => color, :size => 5)
|
200
|
+
palette = Paleta::Palette.generate(:type => :triad, :from => :color, :color => color, :size => 5)
|
201
201
|
palette.size.should == 5
|
202
202
|
palette.each do |c|
|
203
203
|
c.lightness.should == color.lightness
|
@@ -207,7 +207,7 @@ describe Paleta::Palette do
|
|
207
207
|
|
208
208
|
it "should generate a new tetrad Palette from the seed Color" do
|
209
209
|
color = Paleta::Color.new(:hex, "0066cc")
|
210
|
-
palette = Paleta::Palette.generate(:type => :tetrad, :from => color, :size => 5)
|
210
|
+
palette = Paleta::Palette.generate(:type => :tetrad, :from => :color, :color => color, :size => 5)
|
211
211
|
palette.size.should == 5
|
212
212
|
palette.each do |c|
|
213
213
|
c.lightness.should == color.lightness
|
@@ -217,11 +217,22 @@ describe Paleta::Palette do
|
|
217
217
|
|
218
218
|
it "should generate a new split-complement Palette from the seed Color" do
|
219
219
|
color = Paleta::Color.new(:hex, "0066cc")
|
220
|
-
palette = Paleta::Palette.generate(:type => :split_complement, :from => color, :size => 5)
|
220
|
+
palette = Paleta::Palette.generate(:type => :split_complement, :from => :color, :color => color, :size => 5)
|
221
221
|
palette.size.should == 5
|
222
222
|
palette.each do |c|
|
223
223
|
c.lightness.should == color.lightness
|
224
224
|
[color.hue, (color.hue + 150) % 360, (color.hue + 210) % 360].include?(c.hue).should be_true
|
225
225
|
end
|
226
226
|
end
|
227
|
+
|
228
|
+
it "should generate a Palette from an image" do
|
229
|
+
path = File.join(File.dirname(__FILE__), '..', 'images/test.jpg')
|
230
|
+
size = 5
|
231
|
+
palette = Paleta::Palette.generate(:from => :image, :image => path, :size => size)
|
232
|
+
palette.size.should == size
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should raise an error when generating a Palette from an invalid image" do
|
236
|
+
expect{ Paleta::Palette.generate(:from => :image, :image => "/no/image.here") }.to raise_error(RuntimeError)
|
237
|
+
end
|
227
238
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paleta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-02 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: A gem for working with color palettes
|
15
15
|
email:
|
@@ -28,6 +28,7 @@ files:
|
|
28
28
|
- lib/paleta/version.rb
|
29
29
|
- paleta.gemspec
|
30
30
|
- readme.markdown
|
31
|
+
- spec/images/test.jpg
|
31
32
|
- spec/models/color_spec.rb
|
32
33
|
- spec/models/palette_spec.rb
|
33
34
|
- spec/spec_helper.rb
|
@@ -57,6 +58,8 @@ specification_version: 3
|
|
57
58
|
summary: A little library for creating, manipulating and comparing colors and color
|
58
59
|
palettes
|
59
60
|
test_files:
|
61
|
+
- spec/images/test.jpg
|
60
62
|
- spec/models/color_spec.rb
|
61
63
|
- spec/models/palette_spec.rb
|
62
64
|
- spec/spec_helper.rb
|
65
|
+
has_rdoc:
|