color_gradient 0.1.0 → 0.2.0
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/README.md +12 -4
- data/lib/color_gradient/version.rb +1 -1
- data/lib/color_gradient.rb +23 -8
- 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: df58ebf002bbca822db20b5c8f43baf025e758c9
|
|
4
|
+
data.tar.gz: e12510b7a9d0f2278599944cd71fedc74088e122
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 53e20881941e2d7b342a83802a8f7262c307410d58f2086c750164c8a02f7e3ea7f4fe9d5a3e695d2a3322c3edc72a93dccd956902bd475e59ca96f544d77f61
|
|
7
|
+
data.tar.gz: 8ef1ebb766825ced817fee1c1fe61c74f509e32ff3b9e91986b635fd14e55c117468b49dafaa1d22adae950da32a2057cc1f3f1e32981476e3948bc8195ae874
|
data/README.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# ColorGradient
|
|
2
2
|
|
|
3
|
+
[](https://rubygems.org/gems/color_gradient)
|
|
4
|
+
[](https://semaphoreci.com/limeblast/color_gradient)
|
|
5
|
+
[](https://codeclimate.com/github/LimeBlast/color_gradient)
|
|
6
|
+
[](https://codeclimate.com/github/LimeBlast/color_gradient/coverage)
|
|
7
|
+
[](https://codeclimate.com/github/LimeBlast/color_gradient)
|
|
8
|
+
[](https://gemnasium.com/github.com/LimeBlast/color_gradient)
|
|
9
|
+
|
|
3
10
|
This, my first ever gem, takes a [gradient calculation class](http://tnux.net/blog/2011/10/26/gradient-calculation-in-ruby/) created by [Tom Pesman](http://tnux.net/), and makes it use [Color gem](https://github.com/halostatue/color) objects.
|
|
4
11
|
|
|
5
12
|
## Installation
|
|
@@ -36,11 +43,12 @@ color_gradient.gradient(4)
|
|
|
36
43
|
color_gradient.gradient(5)
|
|
37
44
|
color_gradient.gradient(6)
|
|
38
45
|
color_gradient.gradient(7)
|
|
39
|
-
```
|
|
40
46
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
# Or use as enumerable object
|
|
48
|
+
color_gradient.each do |colour|
|
|
49
|
+
do_something(colour)
|
|
50
|
+
end
|
|
51
|
+
```
|
|
44
52
|
|
|
45
53
|
## Development
|
|
46
54
|
|
data/lib/color_gradient.rb
CHANGED
|
@@ -1,27 +1,42 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'color_gradient/version'
|
|
2
|
+
require 'forwardable'
|
|
2
3
|
|
|
3
4
|
class ColorGradient
|
|
5
|
+
include Enumerable
|
|
6
|
+
extend Forwardable
|
|
7
|
+
|
|
8
|
+
def_delegators :result_array, :each, :last, :[]
|
|
9
|
+
|
|
4
10
|
def initialize(start, stop, resolution)
|
|
5
11
|
raise ArgumentError, 'start Argument is not Color gem object' unless start.is_a? Color
|
|
6
12
|
raise ArgumentError, 'stop Argument is not Color gem object' unless stop.is_a? Color
|
|
7
13
|
raise ArgumentError, 'resolution Argument is not integer' unless resolution.is_a? Integer
|
|
8
14
|
|
|
9
|
-
@start
|
|
10
|
-
@stop
|
|
11
|
-
@resolution
|
|
15
|
+
@start = start
|
|
16
|
+
@stop = stop
|
|
17
|
+
@resolution = Float(resolution)
|
|
18
|
+
@result_array = []
|
|
19
|
+
|
|
20
|
+
(resolution+1).times do |i|
|
|
21
|
+
@result_array << generate_step(i)
|
|
22
|
+
end
|
|
12
23
|
end
|
|
13
24
|
|
|
14
25
|
def gradient(step)
|
|
26
|
+
result_array[step]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
attr_accessor :start, :stop, :resolution, :result_array
|
|
32
|
+
|
|
33
|
+
def generate_step(step)
|
|
15
34
|
r = interpolate(start.red.to_i, stop.red.to_i, step)
|
|
16
35
|
g = interpolate(start.green.to_i, stop.green.to_i, step)
|
|
17
36
|
b = interpolate(start.blue.to_i, stop.blue.to_i, step)
|
|
18
37
|
Color::RGB.new(r, g, b)
|
|
19
38
|
end
|
|
20
39
|
|
|
21
|
-
private
|
|
22
|
-
|
|
23
|
-
attr_accessor :start, :stop, :resolution
|
|
24
|
-
|
|
25
40
|
def interpolate(start, stop, step)
|
|
26
41
|
if start < stop
|
|
27
42
|
(((stop - start) * (step / resolution)) + start).round
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: color_gradient
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Hollands
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: exe
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2016-04-
|
|
12
|
+
date: 2016-04-27 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: color
|