rainbow_colors 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c3961da04116805fce98a02d9c90215457f14ec5
4
+ data.tar.gz: c1bcba7fe2e2bb021ded586cbca2ae36660e5986
5
+ SHA512:
6
+ metadata.gz: 733910e9fcdc5c9f7fc4410dfd3453a449af3c58c1d9f5f5d6cfd0d6b5929d1e7ef13ce4bcab7472661946c10cc0aee308851575b0aa88417ea5301dff5539a9
7
+ data.tar.gz: f4ea920eeb36230216316171e62b3c02957bdcc281c1ebc11dbd30b3c8bf21b607fdb859fc6095a7e439da2972e267b428c9d774a1ac93f68ad4acb57b745be7
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rainbow_colors.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ashish Kumar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # RainbowColors
2
+
3
+ Create and generate colour schemes for designs. The following schemes are currently supported:
4
+
5
+ - Analogous
6
+ - Complementary
7
+ - Split-Complementary
8
+ - Triad
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'rainbow_colors'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install rainbow_colors
25
+
26
+ ## Usage
27
+
28
+ TODO: Write usage instructions here
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+
34
+ 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).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ashishkumar/rainbow_colors.
39
+
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
44
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rainbow_colors"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,102 @@
1
+ module RainbowColors
2
+ class Convertor
3
+
4
+ # color_hex => #AB10CD
5
+ def self.rgb_from_hex(color_hex)
6
+ red = (color_hex[1] + color_hex[2]).to_i(16).round
7
+ green = (color_hex[3] + color_hex[4]).to_i(16).round
8
+ blue = (color_hex[5] + color_hex[6]).to_i(16).round
9
+
10
+ { red: red, green: green, blue: blue }
11
+ end
12
+
13
+ # color_rgb => { red: 100, green: 100, blue: 100 }
14
+ def self.hex_from_rgb(color_rgb)
15
+ red = color_rgb[:red] < 16 ? "0" + color_rgb[:red].to_s(16) : color_rgb[:red].to_s(16)
16
+ green = color_rgb[:green] < 16 ? "0" + color_rgb[:green].to_s(16) : color_rgb[:green].to_s(16)
17
+ blue = color_rgb[:blue] < 16 ? "0" + color_rgb[:blue].to_s(16) : color_rgb[:blue].to_s(16)
18
+
19
+ ("##{red}#{green}#{blue}").upcase
20
+ end
21
+
22
+ def self.hsl_from_rgb(color_rgb)
23
+ red = color_rgb[:red] / 255.0
24
+ green = color_rgb[:green] / 255.0
25
+ blue = color_rgb[:blue] / 255.0
26
+
27
+ min = [red, green, blue].min
28
+ max = [red, green, blue].max
29
+ delta_rgb = max - min
30
+
31
+ luminance = (min + max) / 2
32
+
33
+ if delta_rgb == 0
34
+ hue = 0
35
+ saturation = 0
36
+ else
37
+ if luminance < 0.5
38
+ saturation = delta_rgb / (max + min)
39
+ else
40
+ saturation = delta_rgb / (2.0 - max - min)
41
+ end
42
+
43
+ delta_red = (((max - red) / 6.0) + (delta_rgb / 2.0)) / delta_rgb
44
+ delta_green = (((max - green) / 6.0) + (delta_rgb / 2.0)) / delta_rgb
45
+ delta_blue = (((max - blue) / 6.0) + (delta_rgb / 2.0)) / delta_rgb
46
+
47
+ hue = case max
48
+ when red
49
+ delta_blue - delta_green
50
+ when green
51
+ 1.0/3.0 + delta_red - delta_blue
52
+ when blue
53
+ 2.0/3.0 + delta_green - delta_red
54
+ end
55
+ end
56
+
57
+ hue = hue + 1 if hue < 0
58
+ hue = hue - 1 if hue > 1
59
+
60
+ { hue: hue * 360, saturation: saturation * 100, luminance: luminance * 100 }
61
+ end
62
+
63
+ def self.rgb_from_hsl(color_hsl)
64
+ hue = color_hsl[:hue] / 360
65
+ saturation = color_hsl[:saturation] / 100
66
+ luminance = color_hsl[:luminance] / 100
67
+
68
+ red = blue = green = luminance * 255
69
+
70
+ if saturation != 0
71
+ if luminance < 0.5
72
+ v2 = luminance * (1.0 + saturation)
73
+ else
74
+ v2 = (luminance + saturation) - (luminance * saturation)
75
+ end
76
+ v1 = 2.0 * luminance - v2
77
+ red = (255 * rgb_from_hue(v1, v2, 1.0/3.0 + hue)).round
78
+ green = (255 * rgb_from_hue(v1, v2, hue)).round
79
+ blue = (255 * rgb_from_hue(v1, v2, hue - 1.0/3.0)).round
80
+ end
81
+
82
+ { red: red.round, green: green.round, blue: blue.round }
83
+ end
84
+
85
+ private
86
+
87
+ def self.rgb_from_hue(v1, v2, vH)
88
+ vH = vH + 1 if vH < 0
89
+ vH = vH - 1 if vH > 1
90
+
91
+ if vH * 6 < 1
92
+ v1 + (v2 - v1) * 6.0 * vH
93
+ elsif vH * 2 < 1
94
+ v2
95
+ elsif vH * 3 < 2
96
+ v1 + (v2 - v1) * ((2.0/3.0) - vH) * 6
97
+ else
98
+ v1
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,53 @@
1
+ module RainbowColors
2
+ class Palette
3
+ def initialize(primary_color_hex)
4
+ @primary_color = primary_color_hex
5
+ end
6
+
7
+ def self.random_color
8
+ red = rand(255)
9
+ green = rand(255)
10
+ blue = rand(255)
11
+
12
+ RainbowColors::Convertor.hex_from_rgb({ red: red, green: green, blue: blue })
13
+ end
14
+
15
+ def analogous
16
+ secondary = color_with_variance 30
17
+ tertiary = color_with_variance -30
18
+
19
+ { primary: @primary_color, secondary: secondary, tertiary: tertiary }
20
+ end
21
+
22
+ def complementary
23
+ secondary = color_with_variance 180
24
+
25
+ { primary: @primary_color, secondary: secondary }
26
+ end
27
+
28
+ def complementary_split
29
+ secondary = color_with_variance 150
30
+ tertiary = color_with_variance 210
31
+
32
+ { primary: @primary_color, secondary: secondary, tertiary: tertiary }
33
+ end
34
+
35
+ def triad
36
+ secondary = color_with_variance 120
37
+ tertiary = color_with_variance -120
38
+
39
+ { primary: @primary_color, secondary: secondary, tertiary: tertiary }
40
+ end
41
+
42
+ private
43
+
44
+ def color_with_variance(variance)
45
+ rgb = RainbowColors::Convertor.rgb_from_hex @primary_color
46
+ hsl = RainbowColors::Convertor.hsl_from_rgb rgb
47
+
48
+ color = RainbowColors::Convertor.rgb_from_hsl({ hue: hsl[:hue] + variance, saturation: hsl[:saturation], luminance: hsl[:luminance] })
49
+
50
+ RainbowColors::Convertor.hex_from_rgb color
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module RainbowColors
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,3 @@
1
+ require "rainbow_colors/version"
2
+ require "rainbow_colors/convertor"
3
+ require "rainbow_colors/palette"
@@ -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 'rainbow_colors/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rainbow_colors"
8
+ spec.version = RainbowColors::VERSION
9
+ spec.authors = ["Ashish Kumar"]
10
+ spec.email = ["ashish@ashish.co"]
11
+
12
+ spec.summary = "Generate color palettes and schemes for your designs"
13
+ spec.homepage = "https://github.com/ashishkumar/rainbow"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rainbow_colors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ashish Kumar
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-12 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - ashish@ashish.co
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/rainbow_colors.rb
72
+ - lib/rainbow_colors/convertor.rb
73
+ - lib/rainbow_colors/palette.rb
74
+ - lib/rainbow_colors/version.rb
75
+ - rainbow_colors.gemspec
76
+ homepage: https://github.com/ashishkumar/rainbow
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.5.1
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Generate color palettes and schemes for your designs
100
+ test_files: []