color-maker 0.0.1
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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +4 -0
- data/Rakefile +13 -0
- data/color-maker.gemspec +27 -0
- data/lib/color-maker.rb +10 -0
- data/lib/color/array.rb +30 -0
- data/lib/color/hash.rb +51 -0
- data/lib/color/maker.rb +241 -0
- data/lib/color/maker/support.rb +235 -0
- data/lib/color/maker/version.rb +5 -0
- data/lib/color/string.rb +30 -0
- data/lib/colors.yml +148 -0
- data/tags +7561 -0
- data/test/array_test.rb +53 -0
- data/test/hash_test.rb +50 -0
- data/test/maker_test.rb +108 -0
- data/test/string_test.rb +24 -0
- data/test/support_test.rb +74 -0
- data/test/test_helper.rb +3 -0
- metadata +156 -0
data/test/array_test.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe Array do
|
4
|
+
describe 'to_color' do
|
5
|
+
it 'raise error if invalid color format' do
|
6
|
+
a = []
|
7
|
+
proc { a.to_color(:xxx) }.must_raise RuntimeError
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'empty array return black' do
|
11
|
+
a = []
|
12
|
+
color = a.to_color
|
13
|
+
color.hex.must_equal '000000'
|
14
|
+
|
15
|
+
color = a.to_color(:hsv)
|
16
|
+
color.hex.must_equal '000000'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'missing values assume they are 0' do
|
20
|
+
a = [10, 10]
|
21
|
+
color = a.to_color
|
22
|
+
color.hex.must_equal '0a0a00'
|
23
|
+
|
24
|
+
a = [200, 0.7]
|
25
|
+
color = a.to_color(:hsv)
|
26
|
+
color.hex.must_equal '000000'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'h: 200, s: 0.7, v: 0.4' do
|
30
|
+
a = [200, 0.7, 0.4]
|
31
|
+
color = a.to_color(:hsv)
|
32
|
+
color.hex.must_equal '1f4e66'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'r: 255, g: 255, b: 255' do
|
36
|
+
a = [255, 255, 255]
|
37
|
+
color = a.to_color(:rgb)
|
38
|
+
color.hex.must_equal 'ffffff'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'h: 61, s: 0.30, l: 0.55' do
|
42
|
+
a = [61, 0.30, 0.55]
|
43
|
+
color = a.to_color(:hsl)
|
44
|
+
color.hex.must_equal 'aeaf6a'
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'wrong format specified' do
|
48
|
+
a = [255, 255, 255]
|
49
|
+
color = a.to_color(:hsv)
|
50
|
+
color.hex.must_equal '0000ff'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/test/hash_test.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe Hash do
|
4
|
+
describe 'to_color' do
|
5
|
+
it 'raise an error if format is not recognized' do
|
6
|
+
proc { Hash.new.to_color(:xxx) }.must_raise RuntimeError
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'all keys missing return black' do
|
10
|
+
h = { x: 1, y: 2, c: 3 }
|
11
|
+
color = h.to_color(:rgb)
|
12
|
+
color.hex.must_equal '000000'
|
13
|
+
|
14
|
+
color = h.to_color(:hsv)
|
15
|
+
color.hex.must_equal '000000'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'some keys are missing, assume they are 0' do
|
19
|
+
h = { r: 10, g: 10, x: 10 }
|
20
|
+
color = h.to_color(:rgb)
|
21
|
+
color.hex.must_equal '0a0a00'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'empty hash return black' do
|
25
|
+
h = {}
|
26
|
+
color = h.to_color(:hsv)
|
27
|
+
color.hex.must_equal '000000'
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'wrong format specified return black' do
|
31
|
+
h = { r: 255, g: 255, b: 255 }
|
32
|
+
color = h.to_color(:hsv)
|
33
|
+
color.hex.must_equal '000000'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'h: 61, s: 0.30, l: 0.55' do
|
37
|
+
h = { h: 61, s: 0.30, l: 0.55 }
|
38
|
+
color = h.to_color(:hsl)
|
39
|
+
color.hex.must_equal 'aeaf6a'
|
40
|
+
end
|
41
|
+
it 'replace key!' do
|
42
|
+
h = { one: 1, two: 2 }
|
43
|
+
h.replace_key!([:one, :two], :three)
|
44
|
+
h.must_equal({ three: 2 })
|
45
|
+
|
46
|
+
h = { one: 1, two: 2 }
|
47
|
+
h.replace_key!(:one, :three).must_equal({three: 1, two: 2})
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/test/maker_test.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe Color::Maker do
|
4
|
+
it 'golden: false, hue: 12, saturation: 0.7, value: 0.8' do
|
5
|
+
color = Color::Maker.new.make(golden: false, hue: 12, saturation: 0.7, value: 0.8)
|
6
|
+
color.hex.must_equal 'cc5a3d'
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'golden: true, hue: 16, saturation: 0.5, value: 0.65' do
|
10
|
+
color = Color::Maker.new.make(golden: false, hue: 16, saturation: 0.5, value: 0.65)
|
11
|
+
color.hex.must_equal 'a66953'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'golden: false, hue: 10, saturation: 0.6, value: 0.80' do
|
15
|
+
color = Color::Maker.new.make(golden: false, hue: 10, saturation: 0.6, value: 0.80)
|
16
|
+
color.hex.must_equal 'cc6652'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'golden: false, hue: 12, saturation: 0.9, value: 0.3' do
|
20
|
+
color = Color::Maker.new.make(golden: false, hue: 12, saturation: 0.9, value: 0.3)
|
21
|
+
color.hex.must_equal '4d1508'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'grayscale: true, hue: 12' do
|
25
|
+
color = Color::Maker.new.make(grayscale: true, hue: 12, value: 0.3)
|
26
|
+
color.hex.must_equal color.hex[0..1] * 3
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'base_color: :aliceblue' do
|
30
|
+
maker = Color::Maker.new(seed: 1234)
|
31
|
+
color = maker.make(:base_color => :aliceblue)
|
32
|
+
color.hex.must_equal '316d98'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'base_color: rosybrown' do
|
36
|
+
maker = Color::Maker.new(seed: 1234)
|
37
|
+
color = maker.make(:base_color => 'rosybrown')
|
38
|
+
color.hex.must_equal '983136'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'multiple colors' do
|
42
|
+
maker = Color::Maker.new(seed: 1234, count: 5)
|
43
|
+
colors = maker.make
|
44
|
+
colors.size.must_equal 5
|
45
|
+
|
46
|
+
colors.map!(&:hex)
|
47
|
+
colors.must_equal ['aebf73', '73afbf', 'bfb273', '73bf8b', '73bfb8']
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'generator can be overriden inside make method' do
|
51
|
+
maker = Color::Maker.new(seed: 1234, count: 5)
|
52
|
+
colors = maker.make
|
53
|
+
colors.size.must_equal 5
|
54
|
+
|
55
|
+
colors.map!(&:hex)
|
56
|
+
colors.must_equal ['aebf73', '73afbf', 'bfb273', '73bf8b', '73bfb8']
|
57
|
+
|
58
|
+
maker = Color::Maker.new(seed: 1234, count: 5)
|
59
|
+
colors = maker.make(seed: 4444)
|
60
|
+
colors.size.must_equal 5
|
61
|
+
colors.wont_equal ['aebf72', '72afbf', 'bfb272', '72bf8a', '72bfb7']
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'normalize options' do
|
65
|
+
maker = Color::Maker.new
|
66
|
+
|
67
|
+
options = { h: 10, s: 0.9, value: 10 }
|
68
|
+
normalized = maker.send(:normalize_options, options)
|
69
|
+
normalized.must_equal(hue: 10, saturation: 0.9, value: 10)
|
70
|
+
|
71
|
+
options = { hue: 10, s: 0.9, value: 10 }
|
72
|
+
normalized = maker.send(:normalize_options, options)
|
73
|
+
normalized.must_equal(hue: 10, saturation: 0.9, value: 10)
|
74
|
+
|
75
|
+
options = { red: 200, g: 100, blue: 150 }
|
76
|
+
normalized = maker.send(:normalize_options, options)
|
77
|
+
normalized.must_equal(red: 200, green: 100, blue: 150)
|
78
|
+
|
79
|
+
options = { h: 200, g: 100, light: 150 }
|
80
|
+
normalized = maker.send(:normalize_options, options)
|
81
|
+
normalized.must_equal(hue: 200, green: 100, lightness: 150)
|
82
|
+
|
83
|
+
options = { hue: 200, g: 100, lightness: 150, grayscale: true }
|
84
|
+
normalized = maker.send(:normalize_options, options)
|
85
|
+
normalized.must_equal(hue: 200, green: 100, lightness: 150, greyscale: true)
|
86
|
+
|
87
|
+
options = { hue: 200, g: 100, lightness: 150, gray: true }
|
88
|
+
normalized = maker.send(:normalize_options, options)
|
89
|
+
normalized.must_equal(hue: 200, green: 100, lightness: 150, greyscale: true)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'extract color' do
|
93
|
+
maker = Color::Maker.new
|
94
|
+
|
95
|
+
options = { hue: 200, g: 100, lightness: 0.9, gray: true }
|
96
|
+
color = maker.send(:extract_color, options)
|
97
|
+
color.must_equal(h: 0, s: 0, v: 0.004)
|
98
|
+
|
99
|
+
options = { hue: 200, saturation: 0.8, lightness: 0.9, gray: true }
|
100
|
+
color = maker.send(:extract_color, options)
|
101
|
+
color.must_equal(h: 200.5, s: 0.164, v: 0.98)
|
102
|
+
|
103
|
+
options = { red: 200, green: 150, blue: 190, gray: true }
|
104
|
+
color = maker.send(:extract_color, options)
|
105
|
+
color.must_equal(h: 312, s: 0.25, v: 0.784)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
data/test/string_test.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
describe 'to_color' do
|
5
|
+
it 'hex' do
|
6
|
+
hex = '0000ff'
|
7
|
+
hex.to_color(:hex).hex.must_equal '0000ff'
|
8
|
+
|
9
|
+
hex = '0x0000ff'
|
10
|
+
hex.to_color(:hex).hex.must_equal '0000ff'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'html' do
|
14
|
+
'fff'.to_color(:html).hex.must_equal 'ffffff'
|
15
|
+
'#fff'.to_color(:html).hex.must_equal 'ffffff'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'name' do
|
19
|
+
'red'.to_color(:name).hex.must_equal 'ff0000'
|
20
|
+
'blue'.to_color(:name).hex.must_equal '0000ff'
|
21
|
+
'aliceblue'.to_color(:name).hex.must_equal 'f0f8ff'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe Color::Maker::Support do
|
4
|
+
it 'hsv to rgb' do
|
5
|
+
rgb = Color::Maker::Support.hsv_to_rgb({ h: 12, s: 0.9, v: 0.2 })
|
6
|
+
rgb.must_equal ({ r: 51, g: 14, b: 5 })
|
7
|
+
|
8
|
+
rgb = Color::Maker::Support.hsv_to_rgb({ h: 30, s: 0.502, v: 0.898 })
|
9
|
+
rgb.must_equal ({ r: 229, g: 172, b: 114 })
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'hsv to color' do
|
13
|
+
color = Color::Maker::Support.hsv_to_color({ h: 12, s: 0.9, v: 0.2 })
|
14
|
+
color.must_equal Color::RGB.new(51, 14, 5)
|
15
|
+
|
16
|
+
color = Color::Maker::Support.hsv_to_color({ h: 30, s: 0.502, v: 0.898 })
|
17
|
+
color.must_equal Color::RGB.new(229, 172, 114)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'hex to color' do
|
21
|
+
hex = '#0000ff'
|
22
|
+
color = Color::Maker::Support.hex_to_color(hex)
|
23
|
+
color.must_equal Color::RGB.by_hex(hex)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'string to color' do
|
27
|
+
hex = '0000ff'
|
28
|
+
color = hex.to_color
|
29
|
+
color.must_equal Color::RGB.by_hex(hex)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'rgb to hsv' do
|
33
|
+
hsv = Color::Maker::Support.rgb_to_hsv(r: 15, g: 193, b: 17)
|
34
|
+
hsv.must_equal({ h: 120.7, s: 0.922, v: 0.757 })
|
35
|
+
|
36
|
+
hsv = Color::Maker::Support.rgb_to_hsv(r: 25, g: 115, b: 189)
|
37
|
+
hsv.must_equal({ h: 207.1, s: 0.868, v: 0.741 })
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'rgb to hsl' do
|
41
|
+
hsl = Color::Maker::Support.rgb_to_hsl(r: 15, g: 193, b: 17)
|
42
|
+
hsl.must_equal({ h: 120.7, s: 0.856, l: 0.408 })
|
43
|
+
|
44
|
+
hsl = Color::Maker::Support.rgb_to_hsl(r: 25, g: 115, b: 189)
|
45
|
+
hsl.must_equal({ h: 207.1, s: 0.766, l: 0.42 })
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'hsl to rgb' do
|
49
|
+
rgb = Color::Maker::Support.hsl_to_rgb(h: 120.7, s: 0.856, l: 0.408)
|
50
|
+
rgb.must_equal({ r: 15, g: 193, b: 17 })
|
51
|
+
|
52
|
+
rgb = Color::Maker::Support.hsl_to_rgb(h: 207.1, s: 0.766, l: 0.42)
|
53
|
+
rgb.must_equal({ r: 25, g: 115, b: 189 })
|
54
|
+
|
55
|
+
rgb = Color::Maker::Support.hsl_to_rgb(h: 61, s: 0.30, l: 0.55)
|
56
|
+
rgb.must_equal({ r: 174, g: 175, b: 106 })
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'hsl to hsv' do
|
60
|
+
hsv = Color::Maker::Support.hsl_to_hsv(h: 120.7, s: 0.856, l: 0.408)
|
61
|
+
hsv.must_equal({ h: 120.7, s: 0.922, v: 0.757 })
|
62
|
+
|
63
|
+
hsv = Color::Maker::Support.hsl_to_hsv(h: 207.1, s: 0.766, l: 0.42)
|
64
|
+
hsv.must_equal({ h: 207.1, s: 0.868, v: 0.741 })
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'hsv to hsl' do
|
68
|
+
hsl = Color::Maker::Support.hsv_to_hsl(h: 120.7, s: 0.922, v: 0.757)
|
69
|
+
hsl.must_equal({ h: 120.7, s: 0.856, l: 0.408 })
|
70
|
+
|
71
|
+
hsl = Color::Maker::Support.hsv_to_hsl(h: 207.1, s: 0.868, v: 0.741)
|
72
|
+
hsl.must_equal({ h: 207.1, s: 0.766, l: 0.42 })
|
73
|
+
end
|
74
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: color-maker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Viorel Craescu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: color
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.6'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.6'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
description: Color generator
|
98
|
+
email:
|
99
|
+
- viorel@craescu.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- color-maker.gemspec
|
110
|
+
- lib/color-maker.rb
|
111
|
+
- lib/color/array.rb
|
112
|
+
- lib/color/hash.rb
|
113
|
+
- lib/color/maker.rb
|
114
|
+
- lib/color/maker/support.rb
|
115
|
+
- lib/color/maker/version.rb
|
116
|
+
- lib/color/string.rb
|
117
|
+
- lib/colors.yml
|
118
|
+
- tags
|
119
|
+
- test/array_test.rb
|
120
|
+
- test/hash_test.rb
|
121
|
+
- test/maker_test.rb
|
122
|
+
- test/string_test.rb
|
123
|
+
- test/support_test.rb
|
124
|
+
- test/test_helper.rb
|
125
|
+
homepage: ''
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.4.1
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: Color generator
|
149
|
+
test_files:
|
150
|
+
- test/array_test.rb
|
151
|
+
- test/hash_test.rb
|
152
|
+
- test/maker_test.rb
|
153
|
+
- test/string_test.rb
|
154
|
+
- test/support_test.rb
|
155
|
+
- test/test_helper.rb
|
156
|
+
has_rdoc:
|