gradient 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/gradient/grd.rb +2 -2
- data/lib/gradient/map.rb +20 -26
- data/lib/gradient/version.rb +1 -1
- 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: b8a4cda55417c291a922c291959867947aa8b93a
|
4
|
+
data.tar.gz: a5a1564b1ae76f25ebb4eed1f804123fa9cf6102
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edf334904f263f9bfd9274d5f4cec5712c309c5b9a41e0032b982eee016edb76292da173dd2fb6cecedca30dd1ca963669b6c396e34d61d7ce0aa8742424980a
|
7
|
+
data.tar.gz: 68cc22eacc507b58b6d40bbc4bfca6919f328e53a0dfa06ced5f378e3dd0a576566e0e7034e6114369b5fbbd9c950ecbff8990d04daac8f586122b7ed3024a57
|
data/lib/gradient/grd.rb
CHANGED
@@ -115,13 +115,13 @@ module Gradient
|
|
115
115
|
|
116
116
|
private def convert_to_color(color_data)
|
117
117
|
case format = color_data["palette"]
|
118
|
-
when "CMYC" then Color::CMYK.from_percent(*color_data.values_at("Cyn", "Mgnt", "Ylw", "Blck").map(&:round))
|
118
|
+
when "CMYC" then Color::CMYK.from_percent(*color_data.values_at("Cyn", "Mgnt", "Ylw", "Blck").map(&:round)).to_rgb
|
119
119
|
when "RGBC" then Color::RGB.new(*color_data.values_at("Rd", "Grn", "Bl").map(&:round))
|
120
120
|
when "HSBC"
|
121
121
|
h = color_data.fetch("H")
|
122
122
|
s = color_data.fetch("Strt") / 100.0
|
123
123
|
l = color_data.fetch("Brgh") / 100.0
|
124
|
-
Color::HSL.from_fraction(h, s, l)
|
124
|
+
Color::HSL.from_fraction(h, s, l).to_rgb
|
125
125
|
else
|
126
126
|
raise NotImplementedError.new("The color #{format} is not supported")
|
127
127
|
end
|
data/lib/gradient/map.rb
CHANGED
@@ -10,7 +10,7 @@ module Gradient
|
|
10
10
|
@opacity_points = sort_points(Array(opacity_points))
|
11
11
|
@all_points = sort_points(@color_points + @opacity_points)
|
12
12
|
@locations = @all_points.map { |point| point.location }.uniq
|
13
|
-
@points ||=
|
13
|
+
@points ||= merge_color_and_opacity_points
|
14
14
|
end
|
15
15
|
|
16
16
|
def inspect
|
@@ -22,43 +22,37 @@ module Gradient
|
|
22
22
|
@css_printer.css(**args)
|
23
23
|
end
|
24
24
|
|
25
|
-
private def
|
26
|
-
|
25
|
+
private def merge_color_and_opacity_points
|
26
|
+
@locations.map do |location|
|
27
27
|
selected_points = @all_points.select { |point| point.location == location }
|
28
|
-
|
29
|
-
if
|
30
|
-
|
31
|
-
elsif
|
32
|
-
point =
|
33
|
-
a, b =
|
28
|
+
colored, opaque = selected_points.group_by(&:class).values_at(ColorPoint, OpacityPoint)
|
29
|
+
rgba = if colored && opaque
|
30
|
+
[colored.first.color, opaque.first.opacity]
|
31
|
+
elsif colored
|
32
|
+
point = colored.first
|
33
|
+
a, b = adjacent_points(@opacity_points, point)
|
34
34
|
fraction = location_fraction(a, b, point)
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
a, b = previous_and_next_in(@color_points, point)
|
35
|
+
[point.color, opacity_difference(fraction, a, b)]
|
36
|
+
elsif opaque
|
37
|
+
point = opaque.first
|
38
|
+
a, b = adjacent_points(@color_points, point)
|
40
39
|
fraction = location_fraction(a, b, point)
|
41
|
-
|
42
|
-
Gradient::Point.new(location, color, point.opacity)
|
40
|
+
[color_difference(fraction, a, b), point.opacity]
|
43
41
|
end
|
42
|
+
|
43
|
+
Gradient::Point.new(location, *rgba)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
private def
|
48
|
-
groups = bucket.group_by { |p|
|
47
|
+
private def adjacent_points(bucket, point)
|
48
|
+
groups = bucket.group_by { |p| triage_point(p, point) }
|
49
49
|
a = groups.fetch(:same) { groups.fetch(:less) { groups.fetch(:more) } }.max { |p| p.location }
|
50
50
|
b = groups.fetch(:same) { groups.fetch(:more) { groups.fetch(:less) } }.min { |p| p.location }
|
51
51
|
return a, b
|
52
52
|
end
|
53
53
|
|
54
|
-
private def
|
55
|
-
|
56
|
-
:less
|
57
|
-
elsif a.location > b.location
|
58
|
-
:more
|
59
|
-
else
|
60
|
-
:same
|
61
|
-
end
|
54
|
+
private def triage_point(a, b)
|
55
|
+
a.location < b.location ? :less : (a.location > b.location ? :more : :same)
|
62
56
|
end
|
63
57
|
|
64
58
|
private def color_difference(fraction, a, b)
|
data/lib/gradient/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gradient
|
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
|
- Philip Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: color
|