pigment 0.1.1 → 0.1.2
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.
- data/lib/pigment.rb +42 -13
- metadata +5 -5
data/lib/pigment.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Pigment
|
2
|
-
VERSION = '0.1.
|
2
|
+
VERSION = '0.1.2'
|
3
3
|
|
4
4
|
class Color
|
5
5
|
|
@@ -8,7 +8,7 @@ module Pigment
|
|
8
8
|
|
9
9
|
# Pigment uses sRGB or sRGBA as the default color system
|
10
10
|
# color can be a hexadecimal code preceded by a '#' like '#FF4CB2' or a array of floats (1.0, 0.3, 0.7)
|
11
|
-
# or an array of integers between 0 and 255 ()
|
11
|
+
# or an array of integers between 0 and 255 (153, 255, 31)
|
12
12
|
# @param [String, Array] color
|
13
13
|
def initialize(*color)
|
14
14
|
@color = case
|
@@ -36,6 +36,16 @@ module Pigment
|
|
36
36
|
define_method("#{m}", ->() { hsl[i] })
|
37
37
|
end
|
38
38
|
|
39
|
+
# Set alpha value. Only accepts float values
|
40
|
+
# @param [Float] alpha
|
41
|
+
def a=(alpha)
|
42
|
+
@color[3] = alpha if alpha.is_a?(Float) && (0.0..1.0).include?(alpha)
|
43
|
+
end
|
44
|
+
|
45
|
+
def rgb
|
46
|
+
@color[0, 3]
|
47
|
+
end
|
48
|
+
|
39
49
|
# Return specified color by its name from the named_colors hash.
|
40
50
|
# @param [Symbol] name
|
41
51
|
# @return [Color]
|
@@ -69,9 +79,7 @@ module Pigment
|
|
69
79
|
# @param [Array] color
|
70
80
|
# @return [Array]
|
71
81
|
def self.supress(color)
|
72
|
-
unless (0.0..1.0).include?(color.max)
|
73
|
-
color.map! { |c| c / color.max }
|
74
|
-
end
|
82
|
+
color.map! { |c| c / color.max } unless (0.0..1.0).include?(color.max)
|
75
83
|
color
|
76
84
|
end
|
77
85
|
|
@@ -108,19 +116,24 @@ module Pigment
|
|
108
116
|
def +(color)
|
109
117
|
case color
|
110
118
|
when Color
|
111
|
-
self.class.new(*supress([color.
|
119
|
+
self.class.new(*supress([color.rgb, rgb].transpose.map! { |c, d| c + d }))
|
112
120
|
else
|
113
121
|
raise ArgumentError, "Expecting Color. Given #{color.class}"
|
114
122
|
end
|
115
123
|
end
|
116
124
|
|
117
125
|
# Subtracts all the two color components. If any component gets out of the 0 to 1.0 range its supressed.
|
126
|
+
# If tone component gets lower than 0 it acts like its dealing with the inverse component -> 1 - component
|
118
127
|
# @param [Numeric] color
|
119
128
|
# @return [Color]
|
120
129
|
def -(color)
|
121
130
|
case color
|
122
131
|
when Color
|
123
|
-
self.class.new(*supress([color
|
132
|
+
self.class.new(*self.class.supress([@color, color.color].transpose.map! do |c, d|
|
133
|
+
e = c - d
|
134
|
+
e >= 0 ? e : e = 1 + e
|
135
|
+
e
|
136
|
+
end))
|
124
137
|
else
|
125
138
|
raise ArgumentError, "Expecting color. Given #{color.class}"
|
126
139
|
end
|
@@ -132,7 +145,7 @@ module Pigment
|
|
132
145
|
def *(n)
|
133
146
|
case n
|
134
147
|
when Numeric
|
135
|
-
n =
|
148
|
+
n = rgb.map { |c| c * n.to_f }
|
136
149
|
self.class.new(*self.class.supress(n))
|
137
150
|
else
|
138
151
|
raise ArgumentError, "Expecting Numeric. Given #{n.class}"
|
@@ -145,7 +158,7 @@ module Pigment
|
|
145
158
|
def /(n)
|
146
159
|
case n
|
147
160
|
when Numeric
|
148
|
-
n =
|
161
|
+
n = rgb.map { |c| c * n.to_f }
|
149
162
|
self.class.new(*self.class.supress(n))
|
150
163
|
else
|
151
164
|
raise ArgumentError, "Expecting Numeric. Given #{n.class}"
|
@@ -156,9 +169,15 @@ module Pigment
|
|
156
169
|
# @param [Color] color
|
157
170
|
# @return [Boolean]
|
158
171
|
def ==(color)
|
159
|
-
color.is_a? Color && color.
|
172
|
+
color.is_a? Color && color.rgb == @color.rgb
|
160
173
|
end
|
161
174
|
|
175
|
+
# Converts a color to its grayscale correspondent
|
176
|
+
# @return [Color]
|
177
|
+
def grayscale
|
178
|
+
r = g = b = (self.r + self.g + self.b)/3
|
179
|
+
self.class.new(r, g, b)
|
180
|
+
end
|
162
181
|
|
163
182
|
# Calculates the harmonic colors. Type can be :triadic, :split, :analogous, :complement or :complementary
|
164
183
|
# @param [Symbol] type
|
@@ -197,11 +216,21 @@ module Pigment
|
|
197
216
|
self.class.new(*@color.map { |c| 1.0 - c })
|
198
217
|
end
|
199
218
|
|
219
|
+
# Returns a new Color without the given channels
|
220
|
+
# @param [Array of Symbols] channels
|
221
|
+
# @return [Color]
|
222
|
+
def remove_channels(*channels)
|
223
|
+
r = 0 if channels.include? :r
|
224
|
+
g = 0 if channels.include? :g
|
225
|
+
b = 0 if channels.include? :b
|
226
|
+
self.class.new(r, g, b)
|
227
|
+
end
|
228
|
+
|
200
229
|
# Creates an instance variable to keep the HSL values of a RGB color.
|
201
230
|
# @return [Array]
|
202
231
|
def to_hsl
|
203
|
-
min =
|
204
|
-
max =
|
232
|
+
min = rgb.min
|
233
|
+
max = rgb.max
|
205
234
|
delta = (max - min)
|
206
235
|
l = (max + min) / 2.0
|
207
236
|
|
@@ -232,7 +261,7 @@ module Pigment
|
|
232
261
|
# @param [Boolean] with_alpha
|
233
262
|
# @return [Array]
|
234
263
|
def to_floats(with_alpha = false)
|
235
|
-
with_alpha ? @color :
|
264
|
+
with_alpha ? @color : rgb
|
236
265
|
end
|
237
266
|
|
238
267
|
# Returns an array of the color components. Alpha value is passed as well if with_alpha is set to true.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pigment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,10 +10,10 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-11-
|
13
|
+
date: 2012-11-16 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: A rgb color gem, with a list of 750 diferent colors defined within 869
|
16
|
-
names
|
16
|
+
names.
|
17
17
|
email:
|
18
18
|
- pedro.megastore@gmail.com
|
19
19
|
- silver.phoenix99@gmail.com
|
@@ -23,7 +23,7 @@ extra_rdoc_files: []
|
|
23
23
|
files:
|
24
24
|
- lib/colors.rb
|
25
25
|
- lib/pigment.rb
|
26
|
-
homepage: https://github.com/
|
26
|
+
homepage: https://github.com/SilverPhoenix99/roglew
|
27
27
|
licenses: []
|
28
28
|
post_install_message:
|
29
29
|
rdoc_options: []
|
@@ -46,5 +46,5 @@ rubyforge_project:
|
|
46
46
|
rubygems_version: 1.8.24
|
47
47
|
signing_key:
|
48
48
|
specification_version: 3
|
49
|
-
summary: A
|
49
|
+
summary: A rgb color gem, with a list of 750 diferent colors.
|
50
50
|
test_files: []
|