rainbow_gradient 0.0.3 → 0.0.4
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/example/gradient.rb +3 -3
- data/example/output/gradient.png +0 -0
- data/lib/rainbow/color_range.rb +7 -6
- data/lib/rainbow/gradient.rb +9 -2
- data/lib/rainbow/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6afc3a25da96213fd5439117416ca690e846ea6
|
4
|
+
data.tar.gz: a5008ab52fabc12e3c2f0338e7153e473dd810ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2404fe524777e063bdda3efceebd73998581c9d3afcaf409188ae5763ae066f9ee8695bea1be552d425525fda5314a0450cd5d54a526d4124a5049f507b4d48e
|
7
|
+
data.tar.gz: b4f34e44069723f2385bee090b16966fadf137e5fd02d6ca81794e91366f51f169d17092adc91597e5101f2882d69762216cbe8813a7f3b6ca0b0ee709db4ab4
|
data/example/gradient.rb
CHANGED
@@ -2,10 +2,10 @@ require_relative '../lib/rainbow'
|
|
2
2
|
require 'pp'
|
3
3
|
|
4
4
|
first_color = Rainbow::Color.new(ChunkyPNG::Color(255, 221, 23), 0)
|
5
|
-
second_color = Rainbow::Color.new(ChunkyPNG::Color(255, 221, 23),
|
5
|
+
second_color = Rainbow::Color.new(ChunkyPNG::Color(255, 221, 23), 62)
|
6
6
|
color_range1 = Rainbow::ColorRange.new(first_color, second_color, 50)
|
7
7
|
|
8
|
-
third_color = Rainbow::Color.new(ChunkyPNG::Color(255, 221, 23),
|
8
|
+
third_color = Rainbow::Color.new(ChunkyPNG::Color(255, 221, 23), 63)
|
9
9
|
color_range2 = Rainbow::ColorRange.new(second_color, third_color, 50)
|
10
10
|
|
11
11
|
fouth_color = Rainbow::Color.new(ChunkyPNG::Color(255, 221, 23), 100)
|
@@ -28,7 +28,7 @@ args = {
|
|
28
28
|
opacity_ranges: [opacity_range]
|
29
29
|
}
|
30
30
|
}
|
31
|
-
gradient = Rainbow::Gradient.new(
|
31
|
+
gradient = Rainbow::Gradient.new(196, 28, args)
|
32
32
|
gradient.save_as_png(filename)
|
33
33
|
|
34
34
|
`open #{filename}`
|
data/example/output/gradient.png
CHANGED
Binary file
|
data/lib/rainbow/color_range.rb
CHANGED
@@ -7,14 +7,15 @@ module Rainbow
|
|
7
7
|
attr_reader :tmp_current_x, :tmp_diff_r, :tmp_diff_g, :tmp_diff_b,
|
8
8
|
:tmp_from_color, :tmp_to_color, :tmp_distance_in_pixel
|
9
9
|
|
10
|
-
attr_accessor :opacity_ranges
|
10
|
+
attr_accessor :opacity_ranges, :previous
|
11
11
|
|
12
12
|
def initialize(from_color, to_color, mid_point)
|
13
13
|
@from_color = from_color
|
14
14
|
@to_color = to_color
|
15
15
|
@mid_point = mid_point
|
16
16
|
|
17
|
-
@current_x
|
17
|
+
@current_x = nil
|
18
|
+
@previous = nil
|
18
19
|
end
|
19
20
|
|
20
21
|
def gradient=(gradient)
|
@@ -59,15 +60,15 @@ module Rainbow
|
|
59
60
|
from_color.g + (to_color.g - from_color.g) / 2,
|
60
61
|
from_color.b + (to_color.b - from_color.b) / 2)
|
61
62
|
|
62
|
-
@width = (gradient.width * (to_color.location - from_color.location) / 100.0).
|
63
|
-
@first_width = (@width * mid_point / 100.0).
|
63
|
+
@width = (gradient.width * (to_color.location - from_color.location) / 100.0).ceil
|
64
|
+
@first_width = (@width * mid_point / 100.0).ceil
|
64
65
|
@second_width = @width - @first_width
|
65
66
|
|
66
|
-
@from_location_in_pixel = (from_color.location * gradient.width / 100.0).
|
67
|
+
@from_location_in_pixel = (from_color.location * gradient.width / 100.0).ceil
|
67
68
|
@mid_location_in_pixel = @from_location_in_pixel + @first_width
|
68
69
|
@to_location_in_pixel = @from_location_in_pixel + @width
|
69
70
|
|
70
|
-
@leftover_width = ((100 - to_color.location) * gradient.width / 100.0).
|
71
|
+
@leftover_width = ((100 - to_color.location) * gradient.width / 100.0).ceil
|
71
72
|
end
|
72
73
|
|
73
74
|
def in_scale_range?
|
data/lib/rainbow/gradient.rb
CHANGED
@@ -139,8 +139,11 @@ module Rainbow
|
|
139
139
|
end
|
140
140
|
|
141
141
|
def paint_canvas!(canvas)
|
142
|
-
x_coverred
|
142
|
+
x_coverred = 0
|
143
|
+
previous_color_range = nil
|
144
|
+
|
143
145
|
color_ranges.each_with_index do |color_range, index|
|
146
|
+
color_range.previous = previous_color_range
|
144
147
|
color_range.gradient = self
|
145
148
|
color_range.opacity_ranges = opacity_ranges
|
146
149
|
|
@@ -151,6 +154,8 @@ module Rainbow
|
|
151
154
|
|
152
155
|
# When the last color location is not 100
|
153
156
|
x_coverred += paint_suffix(canvas, color_range, x_coverred) if index + 1 == color_ranges.size
|
157
|
+
|
158
|
+
previous_color_range = color_range if index != 0
|
154
159
|
end
|
155
160
|
end
|
156
161
|
|
@@ -164,9 +169,11 @@ module Rainbow
|
|
164
169
|
end
|
165
170
|
|
166
171
|
def paint_body(canvas, color_range, x_coverred)
|
167
|
-
|
168
172
|
color_range.width.times do |x|
|
169
173
|
x += x_coverred
|
174
|
+
|
175
|
+
break if x == width
|
176
|
+
|
170
177
|
color_range.current_x = x
|
171
178
|
height.times { |y| canvas[x, y] = color_range.current_color }
|
172
179
|
end
|
data/lib/rainbow/version.rb
CHANGED