color-palette 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/lib/color-palette.rb +72 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 881b2545358c5c4b066e449e3ed1aade45fd4be7
|
4
|
+
data.tar.gz: 5b534bae0113da17d4d9547e8c6b2c5108af2a58
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3f143728341965b4e014de9337972fa04711356014462c50170042ec7d810eef9e9c65ef3ba37c0348edd03b00da7d85c7033135abac94e14bba44525cde0f4d
|
7
|
+
data.tar.gz: 0e3ace3885c96e1c1315ff3d5055219ad3527af589fd9a764367f421943178c881442bc11b1906773004871e130a725f9d8382fa3feb3edaa1cf0fe1f5f12dd1
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#color-palette.rb
|
2
|
+
require 'pry'
|
3
|
+
class ColorPalette
|
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
|
69
|
+
|
70
|
+
# cp = ColorPalette.new
|
71
|
+
# colors = cp.get_colors_arrays(20)
|
72
|
+
# puts ColorPalette.palette(4)
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: color-palette
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Avinash Vallabhaneni
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple color gem that returns you with a palette of colors which are
|
14
|
+
web friendly and easy to use.
|
15
|
+
email: avinash.vllbh@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/color-palette.rb
|
21
|
+
homepage: http://rubygems.org/gems/color-palette
|
22
|
+
licenses:
|
23
|
+
- None
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.2.2
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Palette of colors to choose from.
|
45
|
+
test_files: []
|