colour 0.3 → 0.4.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.
- data/Gemfile +7 -0
- data/Gemfile.lock +28 -0
- data/LICENSE.txt +20 -0
- data/Rakefile +36 -14
- data/VERSION +1 -0
- data/colour.gemspec +0 -0
- data/lib/colour.rb +116 -158
- data/lib/gradient.rb +23 -0
- data/lib/hsv.rb +5 -5
- data/lib/standard_colours.rb +267 -268
- data/spec/gradient_spec.rb +17 -0
- data/spec/hsv_spec.rb +9 -0
- data/spec/rgb_spec.rb +9 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/color_representation.rb +86 -0
- metadata +68 -24
- data/History.txt +0 -5
- data/Manifest.txt +0 -11
- data/colour.rb +0 -5
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
red = StandardColoursRGB.red
|
4
|
+
white = StandardColoursRGB.white
|
5
|
+
|
6
|
+
describe Gradient do
|
7
|
+
it "should be initialized with two colours" do
|
8
|
+
Gradient.new(red, white)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should provide a colour at distance between two colours" do
|
12
|
+
c = Gradient.new(red,white).colour_at(0.5)
|
13
|
+
c.to_rgb.g.should eql(0.5)
|
14
|
+
c.to_rgb.b.should eql(0.5)
|
15
|
+
c.to_rgb.r.should eql(1.0)
|
16
|
+
end
|
17
|
+
end
|
data/spec/hsv_spec.rb
ADDED
data/spec/rgb_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
green = StandardColoursRGB.green
|
3
|
+
|
4
|
+
|
5
|
+
shared_examples "every colour representation", :shared => true do
|
6
|
+
it "should convert to RGB" do
|
7
|
+
green.should respond_to(:to_rgb)
|
8
|
+
green.to_rgb.g.should eql(1.0)
|
9
|
+
green.to_rgb.b.should eql(0.0)
|
10
|
+
green.to_rgb.r.should eql(0.0)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should convert to HSV" do
|
14
|
+
green.should respond_to(:to_hsv)
|
15
|
+
green.to_hsv.h.should eql(120.0)
|
16
|
+
green.to_hsv.s.should eql(1.0)
|
17
|
+
green.to_hsv.v.should eql(1.0)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should provide a Web Safe Hex" do
|
21
|
+
green.web_safe.should eql("#0F0")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should walk a gradient through the RGB space towards another colour" do
|
25
|
+
gradient = green.gradient_to(RGB.new(1,0,1), steps=3)
|
26
|
+
gradient.size.should eql(3)
|
27
|
+
gradient[0].hex.should eql(green.hex)
|
28
|
+
gradient[1].hex.should eql(RGB.new(0.5, 0.5, 0.5).hex)
|
29
|
+
gradient[2].hex.should eql(RGB.new(1,0,1).hex)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should accept a gradient walk of one step and return the origin" do
|
33
|
+
gradient = green.gradient_to(RGB.new(1,0,1), steps = 1)
|
34
|
+
gradient.size.should eql(1)
|
35
|
+
gradient[0].hex.should eql(green.hex)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should accept a gradient walk for two steps and return the endpoints" do
|
39
|
+
blue = StandardColoursRGB.blue
|
40
|
+
gradient = green.gradient_to(blue, steps = 2)
|
41
|
+
gradient.size.should eql(2)
|
42
|
+
gradient[0].hex.should eql(green.hex)
|
43
|
+
gradient[1].hex.should eql(blue.hex)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should default to a 10 step gradient" do
|
47
|
+
blue = StandardColoursRGB.blue
|
48
|
+
gradient = green.gradient_to(blue)
|
49
|
+
gradient.size.should eql(10)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should provide a complementary colour" do
|
53
|
+
c = green.complementary
|
54
|
+
c.nil?.should eql(false)
|
55
|
+
c.hex.should eql(0xFF00FF)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should provide a split complementary set of colours" do
|
59
|
+
colours = green.split_complementary
|
60
|
+
colours.size.should eql(2)
|
61
|
+
colours[0].hex.should eql(0x7F00FF)
|
62
|
+
colours[1].hex.should eql(0xFF007F)
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
it "should apply a block when generating a split complementary set of colours if one is provided" do
|
67
|
+
i = 0
|
68
|
+
#TODO it would be nice to use the .should_recieve(:blah).and_yeild(:check)
|
69
|
+
# but because this is a shared test, one time we will get RGB, another we get HSV
|
70
|
+
green.split_complementary do |c|
|
71
|
+
if c.hex == 0x7F00FF or c.hex == 0xFF007F then
|
72
|
+
i += 1
|
73
|
+
end
|
74
|
+
end
|
75
|
+
i.should eql(2)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should provide a series of colours rotating around the Hue wheel" do
|
79
|
+
colours = green.rotate_hue(degrees = 36, steps = 11)
|
80
|
+
colours.size.should eql(11)
|
81
|
+
colours[0].hex.should eql(colours[10].hex)
|
82
|
+
colours[4].hex.should eql(0xFF00FF)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colour
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease:
|
5
|
+
version: 0.4.0
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Wes Devauld
|
@@ -9,67 +10,110 @@ autorequire:
|
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
12
|
|
12
|
-
date:
|
13
|
+
date: 2011-09-07 00:00:00 -06:00
|
13
14
|
default_executable:
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
+
name: bundler
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.0
|
24
|
+
type: :development
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jeweler
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.6.4
|
17
35
|
type: :development
|
18
|
-
|
19
|
-
version_requirements:
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rspec
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "2.6"
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rcov
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
20
53
|
requirements:
|
21
54
|
- - ">="
|
22
55
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
24
|
-
|
25
|
-
|
56
|
+
version: "0"
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id004
|
60
|
+
description: Support for computation of colour swatches in both the RGB and HSV colour representations
|
26
61
|
email: wes@devauld.ca
|
27
62
|
executables: []
|
28
63
|
|
29
64
|
extensions: []
|
30
65
|
|
31
66
|
extra_rdoc_files:
|
32
|
-
-
|
67
|
+
- LICENSE.txt
|
33
68
|
- README.txt
|
34
69
|
files:
|
35
|
-
-
|
36
|
-
-
|
70
|
+
- Gemfile
|
71
|
+
- Gemfile.lock
|
72
|
+
- LICENSE.txt
|
37
73
|
- README.txt
|
38
74
|
- Rakefile
|
75
|
+
- VERSION
|
39
76
|
- colour.gemspec
|
40
|
-
- colour.rb
|
41
77
|
- lib/colour.rb
|
78
|
+
- lib/gradient.rb
|
42
79
|
- lib/hsv.rb
|
43
80
|
- lib/rgb.rb
|
44
81
|
- lib/standard_colours.rb
|
82
|
+
- spec/gradient_spec.rb
|
83
|
+
- spec/hsv_spec.rb
|
84
|
+
- spec/rgb_spec.rb
|
85
|
+
- spec/spec_helper.rb
|
86
|
+
- spec/support/color_representation.rb
|
45
87
|
has_rdoc: true
|
46
|
-
homepage: http://
|
88
|
+
homepage: http://github.com/wdevauld/colour
|
89
|
+
licenses:
|
90
|
+
- MIT
|
47
91
|
post_install_message:
|
48
|
-
rdoc_options:
|
49
|
-
|
50
|
-
- README.txt
|
92
|
+
rdoc_options: []
|
93
|
+
|
51
94
|
require_paths:
|
52
95
|
- lib
|
53
96
|
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
54
98
|
requirements:
|
55
99
|
- - ">="
|
56
100
|
- !ruby/object:Gem::Version
|
101
|
+
hash: -752018127558894247
|
102
|
+
segments:
|
103
|
+
- 0
|
57
104
|
version: "0"
|
58
|
-
version:
|
59
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
60
107
|
requirements:
|
61
108
|
- - ">="
|
62
109
|
- !ruby/object:Gem::Version
|
63
110
|
version: "0"
|
64
|
-
version:
|
65
111
|
requirements: []
|
66
112
|
|
67
|
-
rubyforge_project:
|
68
|
-
|
69
|
-
|
70
|
-
rubygems_version: 1.2.0
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 1.6.2
|
71
115
|
signing_key:
|
72
|
-
specification_version:
|
73
|
-
summary:
|
116
|
+
specification_version: 3
|
117
|
+
summary: Colour manipulation library supporting RGB and HSV representations
|
74
118
|
test_files: []
|
75
119
|
|
data/History.txt
DELETED
data/Manifest.txt
DELETED