cpalette 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +31 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +2 -0
- data/cpalette.gemspec +24 -0
- data/lib/cpalette/version.rb +3 -0
- data/lib/cpalette.rb +68 -0
- data/spec/cpalette_spec.rb +7 -0
- data/spec/spec_helper.rb +1 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e045ec02390a31f860c8027a04c5c1bd24321a08
|
4
|
+
data.tar.gz: fb6a2f22a600b79aaaab01cda355a543b9526ba7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: abfad6fb35d0a8e34238223ea7409b3590eff0e7fc49355be3c1822dd8788e8078aaa02cbe2379f0c48bb70acf90ff3305175ff96b64dd030365485982083d2a
|
7
|
+
data.tar.gz: c0c2ec1a3199f3ca88aab20341782d24dfe3128e3de4051c56349979808c75873da7e02ea094a2d8ffc53a9763d4743333e04dc271f609104ef5727cb62afca9
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cpalette (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.5)
|
10
|
+
rake (10.3.2)
|
11
|
+
rspec (3.0.0)
|
12
|
+
rspec-core (~> 3.0.0)
|
13
|
+
rspec-expectations (~> 3.0.0)
|
14
|
+
rspec-mocks (~> 3.0.0)
|
15
|
+
rspec-core (3.0.2)
|
16
|
+
rspec-support (~> 3.0.0)
|
17
|
+
rspec-expectations (3.0.2)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.0.0)
|
20
|
+
rspec-mocks (3.0.2)
|
21
|
+
rspec-support (~> 3.0.0)
|
22
|
+
rspec-support (3.0.2)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
bundler (~> 1.6)
|
29
|
+
cpalette!
|
30
|
+
rake
|
31
|
+
rspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 avinash-vllbh
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Cpalette
|
2
|
+
|
3
|
+
Cpalette
|
4
|
+
----------------------
|
5
|
+
|
6
|
+
A simple color gem that returns you with a palette of colors which are web friendly and easy to use.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'cpalette'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install cpalette
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
TODO: Write usage instructions here
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it ( https://github.com/avinash-vllbh/cpalette/fork )
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/cpalette.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cpalette/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cpalette"
|
8
|
+
spec.version = Cpalette::VERSION
|
9
|
+
spec.authors = ["avinash-vllbh"]
|
10
|
+
spec.email = ["avinash.vallab@gmail.com"]
|
11
|
+
spec.summary = "Palette of colors to choose from."
|
12
|
+
spec.description = "A simple color gem that returns you with a palette of colors which are web friendly and easy to use."
|
13
|
+
spec.homepage = "http://rubygems.org/gems/cpalette"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
data/lib/cpalette.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require "cpalette/version"
|
2
|
+
|
3
|
+
class Cpalette
|
4
|
+
def get_hsl_values_decimal(color)
|
5
|
+
|
6
|
+
end
|
7
|
+
def get_color_codes_in_hex(h, s, l)
|
8
|
+
|
9
|
+
end
|
10
|
+
def self.hue2rgb(p,q,t)
|
11
|
+
t = t + 1 if t < 0
|
12
|
+
t = t -1 if t > 1
|
13
|
+
if 6 * t < 1
|
14
|
+
return p+(q-p)*6*t
|
15
|
+
end
|
16
|
+
if 2 * t < 1
|
17
|
+
return q
|
18
|
+
end
|
19
|
+
if 3 * t < 2
|
20
|
+
return p + (q - p) * ((2.0/3 - t) * 6)
|
21
|
+
end
|
22
|
+
return p
|
23
|
+
end
|
24
|
+
def self.get_color_codes_in_rgb(h, s, l)
|
25
|
+
if s == 0
|
26
|
+
r = g = b = l * 255
|
27
|
+
else
|
28
|
+
if l < 0.5
|
29
|
+
y = l * (1.0 + s)
|
30
|
+
else
|
31
|
+
y = l + s - l * s
|
32
|
+
end
|
33
|
+
x = 2 * l - y
|
34
|
+
r = (255 * hue2rgb(x, y, h + 1.0/3)).round(0)
|
35
|
+
g = (255 * hue2rgb(x, y, h)).round(0)
|
36
|
+
b = (255 * hue2rgb(x, y, h - 1.0/3)).round(0)
|
37
|
+
end
|
38
|
+
return "#{r},#{g},#{b}"
|
39
|
+
end
|
40
|
+
def self.rgb2hex(r, g, b)
|
41
|
+
h1 = r.to_s(16).length == 2 ? r.to_s(16) : "0"+r.to_s(16)
|
42
|
+
h2 = g.to_s(16).length == 2 ? g.to_s(16) : "0"+g.to_s(16)
|
43
|
+
h3 = b.to_s(16).length == 2 ? b.to_s(16) : "0"+b.to_s(16)
|
44
|
+
return "##{h1}#{h2}#{h3}"
|
45
|
+
end
|
46
|
+
def self.palette(size)
|
47
|
+
color_palette = []
|
48
|
+
hue_array = []
|
49
|
+
hue = 359
|
50
|
+
step_size = 360/size
|
51
|
+
for i in 0..size-1
|
52
|
+
hue_array.push(hue)
|
53
|
+
hue = hue - step_size
|
54
|
+
end
|
55
|
+
hue_array.shuffle!
|
56
|
+
hue_array.each do |hue|
|
57
|
+
s = Random.new.rand(60..90)
|
58
|
+
l = Random.new.rand(40..80)
|
59
|
+
color_codes = Hash.new
|
60
|
+
color_codes["hsl"] = "#{hue},#{s}%,#{l}%"
|
61
|
+
color_codes["rgb"] = get_color_codes_in_rgb(hue/360.0,s/100.0,l/100.0)
|
62
|
+
rgb = color_codes["rgb"].split(",")
|
63
|
+
color_codes["hex"] = rgb2hex(rgb[0].to_i, rgb[1].to_i, rgb[2].to_i)
|
64
|
+
color_palette.push(color_codes) unless color_palette.include?(color_codes)
|
65
|
+
end
|
66
|
+
return color_palette
|
67
|
+
end
|
68
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'cpalette'
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cpalette
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- avinash-vllbh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: rspec
|
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
|
+
description: A simple color gem that returns you with a palette of colors which are
|
56
|
+
web friendly and easy to use.
|
57
|
+
email:
|
58
|
+
- avinash.vallab@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- cpalette.gemspec
|
69
|
+
- lib/cpalette.rb
|
70
|
+
- lib/cpalette/version.rb
|
71
|
+
- spec/cpalette_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
homepage: http://rubygems.org/gems/cpalette
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.2.2
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Palette of colors to choose from.
|
97
|
+
test_files:
|
98
|
+
- spec/cpalette_spec.rb
|
99
|
+
- spec/spec_helper.rb
|