colorscheme 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -36,8 +36,7 @@ Or install it yourself as:
36
36
  ## Usage
37
37
 
38
38
  ```
39
- scheme = Colorscheme::Colorscheme.new(Color.RGB.new(255,0,0))
40
- scheme.triadic!
39
+ scheme = Colorscheme::Triadic.new(Color.RGB.new(255,0,0))
41
40
  scheme.colors # is an array of three colors
42
41
  ```
43
42
 
@@ -0,0 +1,29 @@
1
+ module Colorscheme
2
+ module Algorithms
3
+
4
+ def analogous(source, degrees)
5
+ [rotate_color(source, degrees), rotate_color(source, -degrees)]
6
+ end
7
+
8
+ def complementary(source)
9
+ rotate_color(source, 180)
10
+ end
11
+
12
+ def rotate_color(source, degrees)
13
+ hsl = source.to_hsl
14
+ h = 360.0 * hsl.h + degrees
15
+ Color::HSL.new(h, hsl.s * 100, hsl.l * 100).to_rgb
16
+ end
17
+
18
+ def text_color(source)
19
+ sum = source.red + source.green + source.blue
20
+ if sum > 382.5
21
+ return Color::RGB.new(0,0,0)
22
+ else
23
+ return Color::RGB.new(255,255,255)
24
+ end
25
+ end
26
+
27
+
28
+ end
29
+ end
@@ -0,0 +1,10 @@
1
+ require 'colorscheme/colorscheme'
2
+ module Colorscheme
3
+ class Analogous < Colorscheme
4
+ def initialize(color=nil, degrees=30)
5
+ super(color)
6
+ @colors.push(@source_color)
7
+ @colors.concat analogous(@source_color, degrees)
8
+ end
9
+ end
10
+ end
@@ -1,59 +1,12 @@
1
1
  require 'color'
2
+ require 'colorscheme/algorithms'
2
3
  module Colorscheme
3
4
  class Colorscheme
5
+ include Algorithms
4
6
  attr_accessor :colors, :source_color
5
- def initialize(options={})
7
+ def initialize(color=nil)
6
8
  @colors = []
7
- @source_color = options[:source] if options.has_key?(:source)
8
- end
9
-
10
- def complementary!
11
- @colors = []
12
- @colors.push(@source_color)
13
- @colors.push(complementary(@source_color))
14
- end
15
-
16
- def rotate_color(source, degrees)
17
- hsl = source.to_hsl
18
- h = 360.0 * hsl.h + degrees
19
- Color::HSL.new(h, hsl.s * 100, hsl.l * 100).to_rgb
20
- end
21
-
22
- def complementary(source)
23
- rotate_color(source, 180)
24
- end
25
-
26
- def analogous!(degrees)
27
- @colors = []
28
- @colors.push(@source_color)
29
- @colors.concat analogous(@source_color, degrees)
30
- end
31
-
32
- def analogous(source, degrees)
33
- [rotate_color(source, degrees), rotate_color(source, -degrees)]
34
- end
35
-
36
- def split_complementary!(degrees)
37
- @colors = []
38
- @colors.push @source_color
39
- complementary = complementary(@source_color)
40
- analogous_to_complementary = analogous(complementary, degrees)
41
- @colors.push complementary
42
- @colors.concat analogous_to_complementary
43
- end
44
-
45
- def triadic!
46
- @colors = []
47
- @colors.push @source_color
48
- @colors.concat analogous(@source_color, 120)
49
- end
50
-
51
- def squared!
52
- @colors = []
53
- @colors.push @source_color
54
- @colors.push rotate_color(@source_color, 90)
55
- @colors.push rotate_color(@source_color, 180)
56
- @colors.push rotate_color(@source_color, 270)
9
+ @source_color = color
57
10
  end
58
11
  end
59
12
  end
@@ -0,0 +1,10 @@
1
+ require 'colorscheme/colorscheme'
2
+ module Colorscheme
3
+ class Complementary < Colorscheme
4
+ def initialize(color=nil)
5
+ super(color)
6
+ @colors.push(@source_color)
7
+ @colors.push(complementary(@source_color))
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ require 'colorscheme/colorscheme'
2
+ module Colorscheme
3
+ class SplitComplementary < Colorscheme
4
+ def initialize(color=nil, degrees=30)
5
+ super(color)
6
+ @colors.push @source_color
7
+ complementary = complementary(@source_color)
8
+ analogous_to_complementary = analogous(complementary, degrees)
9
+ @colors.push complementary
10
+ @colors.concat analogous_to_complementary
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ require 'colorscheme/colorscheme'
2
+ module Colorscheme
3
+ class Squared < Colorscheme
4
+ def initialize(color=nil)
5
+ super(color)
6
+ @colors.push @source_color
7
+ @colors.push rotate_color(@source_color, 90)
8
+ @colors.push rotate_color(@source_color, 180)
9
+ @colors.push rotate_color(@source_color, 270)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ require 'colorscheme/colorscheme'
2
+ module Colorscheme
3
+ class Triadic < Colorscheme
4
+ def initialize(color=nil)
5
+ super(color)
6
+ @colors.push @source_color
7
+ @colors.push rotate_color(@source_color, 120)
8
+ @colors.push rotate_color(@source_color, 240)
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Colorscheme
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,15 @@
1
+ require 'colorscheme/analogous'
2
+ describe Colorscheme::Analogous do
3
+ it "gets adjacent colors" do
4
+ color = Color::RGB.new(255,0,0)
5
+ adj1 = Color::HSL.new(30,100,50)
6
+ adj2 = Color::HSL.new(-30,100,50)
7
+ scheme = Colorscheme::Analogous.new(color, 30)
8
+
9
+ scheme.colors.first.should equal(color)
10
+ scheme.colors[1].html.should eq(adj1.html)
11
+ scheme.colors.last.html.should eq(adj2.html)
12
+ end
13
+ end
14
+
15
+
@@ -1,12 +1,6 @@
1
1
  require 'colorscheme/colorscheme'
2
2
 
3
3
  describe Colorscheme::Colorscheme do
4
- describe ".new" do
5
- it "can be instantiated by calling new" do
6
- Colorscheme::Colorscheme.new
7
- end
8
- end
9
-
10
4
  describe ".colors" do
11
5
  it "has an array of colors" do
12
6
  scheme = Colorscheme::Colorscheme.new
@@ -17,83 +11,35 @@ describe Colorscheme::Colorscheme do
17
11
  describe ".source_color" do
18
12
  it "sets the source_color on the object" do
19
13
  color = Color::RGB.new(1,2,3)
20
- scheme = Colorscheme::Colorscheme.new({:source => color})
14
+ scheme = Colorscheme::Colorscheme.new(color)
21
15
  scheme.source_color.should equal(color)
22
16
  end
23
17
  end
24
18
 
25
- describe ".complementary" do
26
- it "gets the complementary color as well as the original" do
27
- color = Color::RGB.new(255,0,0)
28
- scheme = Colorscheme::Colorscheme.new({:source => color})
29
- scheme.complementary!
30
- scheme.colors.first.should equal(color)
31
- scheme.colors.last.html.should eq(Color::RGB.new(0,255,255).html)
32
- end
33
- end
34
-
35
- describe ".analogous" do
36
- it "gets adjacent colors" do
37
- color = Color::RGB.new(255,0,0)
38
- adj1 = Color::HSL.new(30,100,50)
39
- adj2 = Color::HSL.new(-30,100,50)
40
- scheme = Colorscheme::Colorscheme.new({:source => color})
41
-
42
- scheme.analogous!(30)
43
-
44
- scheme.colors.first.should equal(color)
45
- scheme.colors[1].html.should eq(adj1.html)
46
- scheme.colors.last.html.should eq(adj2.html)
19
+ describe ".text_color" do
20
+ it "selects black for white source" do
21
+ color = Color::RGB.new(255,255,255)
22
+ scheme = Colorscheme::Colorscheme.new
23
+ text_color = scheme.text_color(color)
24
+ text_color.html.should eq('#000000')
47
25
  end
48
- end
49
-
50
- describe ".split_complementary" do
51
- it "gets the complementary color, and its analogous colors" do
52
- color = Color::RGB.new(0,255,255)
53
- complementary = Color::RGB.new(255,0,0)
54
- adj1 = Color::HSL.new(30,100,50)
55
- adj2 = Color::HSL.new(-30,100,50)
56
- scheme = Colorscheme::Colorscheme.new({:source => color})
57
-
58
- scheme.split_complementary!(30)
59
-
60
- scheme.colors.first.should equal(color)
61
- scheme.colors[1].html.should eq(complementary.html)
62
- scheme.colors[2].html.should eq(adj1.html)
63
- scheme.colors[3].html.should eq(adj2.html)
64
-
26
+ it "selects white for black source" do
27
+ color = Color::RGB.new(0,0,0)
28
+ scheme = Colorscheme::Colorscheme.new
29
+ text_color = scheme.text_color(color)
30
+ text_color.html.should eq('#ffffff')
65
31
  end
66
- end
67
-
68
- describe ".triadic" do
69
- it "gets triadic colors for source" do
70
- color = Color::RGB.new(255,0,0)
71
- triadic1 = Color::RGB.new(0,255,0)
72
- triadic2 = Color::RGB.new(0,0,255)
73
- scheme = Colorscheme::Colorscheme.new({:source => color})
74
-
75
- scheme.triadic!
76
-
77
- scheme.colors.first.should equal(color)
78
- scheme.colors[1].html.should eq(triadic1.html)
79
- scheme.colors[2].html.should eq(triadic2.html)
32
+ it "selects white for #666666" do
33
+ color = Color::RGB.from_html('#666666')
34
+ scheme = Colorscheme::Colorscheme.new
35
+ text_color = scheme.text_color(color)
36
+ text_color.html.should eq('#ffffff')
80
37
  end
81
- end
82
-
83
- describe ".squared" do
84
- it "gets equally spaced colors for source" do
85
- color = Color::RGB.new(255,0,0)
86
- quad1 = Color::HSL.new(90, 100, 50)
87
- quad2 = Color::HSL.new(180, 100, 50)
88
- quad3 = Color::HSL.new(270, 100, 50)
89
- scheme = Colorscheme::Colorscheme.new({:source => color})
90
-
91
- scheme.squared!
92
-
93
- scheme.colors.first.should equal(color)
94
- scheme.colors[1].html.should eq(quad1.html)
95
- scheme.colors[2].html.should eq(quad2.html)
96
- scheme.colors[3].html.should eq(quad3.html)
38
+ it "selects black for #aaaaaa" do
39
+ color = Color::RGB.from_html('#aaaaaa')
40
+ scheme = Colorscheme::Colorscheme.new
41
+ text_color = scheme.text_color(color)
42
+ text_color.html.should eq('#000000')
97
43
  end
98
44
  end
99
45
  end
@@ -0,0 +1,9 @@
1
+ require 'colorscheme/complementary'
2
+ describe Colorscheme::Complementary do
3
+ it "gets the complementary color as well as the original" do
4
+ color = Color::RGB.new(255,0,0)
5
+ scheme = Colorscheme::Complementary.new(color)
6
+ scheme.colors.first.should equal(color)
7
+ scheme.colors.last.html.should eq(Color::RGB.new(0,255,255).html)
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ require 'colorscheme/split_complementary'
2
+ describe Colorscheme::SplitComplementary do
3
+ it "gets the complementary color, and its analogous colors" do
4
+ color = Color::RGB.new(0,255,255)
5
+ complementary = Color::RGB.new(255,0,0)
6
+ adj1 = Color::HSL.new(30,100,50)
7
+ adj2 = Color::HSL.new(-30,100,50)
8
+ scheme = Colorscheme::SplitComplementary.new(color)
9
+
10
+ scheme.colors.first.should equal(color)
11
+ scheme.colors[1].html.should eq(complementary.html)
12
+ scheme.colors[2].html.should eq(adj1.html)
13
+ scheme.colors[3].html.should eq(adj2.html)
14
+
15
+ end
16
+ end
17
+
18
+
@@ -0,0 +1,17 @@
1
+ require 'colorscheme/squared.rb'
2
+ describe Colorscheme::Squared do
3
+ it "gets equally spaced colors for source" do
4
+ color = Color::RGB.new(255,0,0)
5
+ quad1 = Color::HSL.new(90, 100, 50)
6
+ quad2 = Color::HSL.new(180, 100, 50)
7
+ quad3 = Color::HSL.new(270, 100, 50)
8
+ scheme = Colorscheme::Squared.new(color)
9
+
10
+ scheme.colors.first.should equal(color)
11
+ scheme.colors[1].html.should eq(quad1.html)
12
+ scheme.colors[2].html.should eq(quad2.html)
13
+ scheme.colors[3].html.should eq(quad3.html)
14
+ end
15
+ end
16
+
17
+
@@ -0,0 +1,15 @@
1
+ require 'colorscheme/triadic'
2
+ describe Colorscheme::Triadic do
3
+ it "gets triadic colors for source" do
4
+ color = Color::RGB.new(255,0,0)
5
+ triadic1 = Color::RGB.new(0,255,0)
6
+ triadic2 = Color::RGB.new(0,0,255)
7
+ scheme = Colorscheme::Triadic.new(color)
8
+
9
+ scheme.colors.first.should equal(color)
10
+ scheme.colors[1].html.should eq(triadic1.html)
11
+ scheme.colors[2].html.should eq(triadic2.html)
12
+ end
13
+ end
14
+
15
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colorscheme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-08 00:00:00.000000000 Z
12
+ date: 2013-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: color
@@ -74,9 +74,20 @@ files:
74
74
  - Rakefile
75
75
  - colorscheme.gemspec
76
76
  - lib/colorscheme.rb
77
+ - lib/colorscheme/algorithms.rb
78
+ - lib/colorscheme/analogous.rb
77
79
  - lib/colorscheme/colorscheme.rb
80
+ - lib/colorscheme/complementary.rb
81
+ - lib/colorscheme/split_complementary.rb
82
+ - lib/colorscheme/squared.rb
83
+ - lib/colorscheme/triadic.rb
78
84
  - lib/colorscheme/version.rb
85
+ - spec/lib/colorscheme/analogous_spec.rb
79
86
  - spec/lib/colorscheme/colorscheme_spec.rb
87
+ - spec/lib/colorscheme/complementary_spec.rb
88
+ - spec/lib/colorscheme/split_complementary_spec.rb
89
+ - spec/lib/colorscheme/squared_spec.rb
90
+ - spec/lib/colorscheme/triadic_spec.rb
80
91
  - spec/spec_helper.rb
81
92
  homepage: http://clauswitt.com/gems/colorscheme
82
93
  licenses: []
@@ -103,5 +114,10 @@ signing_key:
103
114
  specification_version: 3
104
115
  summary: Given a source - a website, and image or a color - the gem returns a colorscheme
105
116
  test_files:
117
+ - spec/lib/colorscheme/analogous_spec.rb
106
118
  - spec/lib/colorscheme/colorscheme_spec.rb
119
+ - spec/lib/colorscheme/complementary_spec.rb
120
+ - spec/lib/colorscheme/split_complementary_spec.rb
121
+ - spec/lib/colorscheme/squared_spec.rb
122
+ - spec/lib/colorscheme/triadic_spec.rb
107
123
  - spec/spec_helper.rb