rand_palette 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -19
- data/lib/rand_palette.rb +8 -3
- data/lib/rand_palette/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03236522cecb33ba31371d45b6a2c8ad1645bdbf
|
4
|
+
data.tar.gz: 3a4fa073e20cc75df25b598de162b80d9497e93b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb855c140c604d0556cec26a3c7c1316cefa223e8087bbc63fa5586bf1d370b629f5ba396393fe733d7686266554417940f6e12ae3816ab7de57d0faa51a9dca
|
7
|
+
data.tar.gz: 36d4b7a20340de9026147bc9b8e7a01a2913438af658797ea677911e9a93725046e59af57a521df162266180238f772061b1a04b76d6429c5fcfc3e1bdef11d5
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# RandPalette
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Randomly pick distinct color
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,20 +20,10 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/ken/rand_palette. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
-
|
37
|
-
|
38
|
-
## License
|
39
|
-
|
40
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
23
|
+
```ruby
|
24
|
+
irb(main):001:0> RandPalette.random 5
|
25
|
+
=> ["rgba(255,0,221,1)", "rgba(255,85,0,1)", "rgba(119,255,0,1)", "rgba(0,255,187,1)", "rgba(0,17,255,1)"]
|
26
|
+
irb(main):002:0> RandPalette.random 3, alpha: 0.2
|
27
|
+
=> ["rgba(0,255,153,0.2)", "rgba(153,0,255,0.2)", "rgba(255,153,0,0.2)"]
|
28
|
+
```
|
41
29
|
|
data/lib/rand_palette.rb
CHANGED
@@ -13,17 +13,22 @@ module RandPalette
|
|
13
13
|
ScalarDesc.map{|c| [255, 0, c] }].flatten 1
|
14
14
|
|
15
15
|
def self.random n, alpha: 1
|
16
|
-
|
17
|
-
|
16
|
+
raise RangeError, "No more than #{range} kinds od color" if n > range
|
17
|
+
picked = rand range
|
18
|
+
steps = range / n
|
18
19
|
n.times.map do |t|
|
19
20
|
picked = picked + steps
|
20
|
-
picked = picked -
|
21
|
+
picked = picked - range if picked >= range
|
21
22
|
picked
|
22
23
|
end.map do |picked|
|
23
24
|
RGBA.new(Palette[picked] + [alpha]).to_s
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
28
|
+
def self.range
|
29
|
+
Palette.size
|
30
|
+
end
|
31
|
+
|
27
32
|
class RGBA
|
28
33
|
|
29
34
|
def initialize rgba
|
data/lib/rand_palette/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rand_palette
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ken
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|