colorutils 0.0.0

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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/colorutils.gemspec +12 -0
  4. data/lib/colorutils.rb +27 -0
  5. metadata +47 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a745563ae321a3a4e15346c94f6aa63e0f772610
4
+ data.tar.gz: 6ff7b154bd415dcff8293afa8c93122a50dec497
5
+ SHA512:
6
+ metadata.gz: b5ee994d08b5a1d340b9cbcd0a4b1eadf54717fb3082b48e7488caed2081a964880b88123952e2bacad7057089b4b139e7e62982752e891097c9c7efcd005f3f
7
+ data.tar.gz: c7ba272f70030e462a2aa5faa97984ccef087f62354b3692abd33052cc45ed19a55f90efc821ab155518309c060329085f21ddd6a0d266946eee262a555daeb2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Victor Maslov
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,12 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "colorutils"
3
+ spec.version = "0.0.0"
4
+ spec.summary = "Common methods to work with colors."
5
+
6
+ spec.author = "Victor Maslov aka Nakilon"
7
+ spec.email = "nakilon@gmail.com"
8
+ spec.license = "MIT"
9
+ spec.metadata = {"source_code_uri" => "https://github.com/nakilon/colorutils"}
10
+
11
+ spec.files = %w{ LICENSE colorutils.gemspec lib/colorutils.rb }
12
+ end
data/lib/colorutils.rb ADDED
@@ -0,0 +1,27 @@
1
+ module ColorUtils
2
+ def self.rgb2hsv r, g, b # [<256, <256, <256]
3
+ # http://stackoverflow.com/q/41926874/322020
4
+ r, g, b = [r, g, b].map{ |_| _.fdiv 255 }
5
+ min, max = [r, g, b].minmax
6
+ chroma = max - min
7
+ [
8
+ 60.0 * ( chroma.zero? ? 0 : case max
9
+ when r ; (g - b) / chroma
10
+ when g ; (b - r) / chroma + 2
11
+ when b ; (r - g) / chroma + 4
12
+ else 0
13
+ end % 6 ),
14
+ chroma.zero? ? 0.0 : chroma / max,
15
+ max,
16
+ ] # [<=360, <=1, <=1]
17
+ end
18
+ def self.dist h1, s1, v1, h2, s2, v2 # [<256, <256, <256]
19
+ # https://en.wikipedia.org/wiki/HSL_and_HSV#/media/File:Hsl-hsv_saturation-lightness_slices.svg
20
+ c1, c2 = s1 * v1 / 256.0, s2 * v2 / 256.0 # chroma
21
+ z1, z2 = v1 * (2 - c1 / 256), v2 * (2 - c2 / 256)
22
+ a = (((h2 - h1) * 360 / 256.0) % 360) / (180 / Math::PI)
23
+ x2 = Math::sin(a) * c2
24
+ y1, y2 = c1, Math::cos(a) * c2
25
+ x2*x2 + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2)
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: colorutils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Victor Maslov aka Nakilon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-05-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: nakilon@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE
20
+ - colorutils.gemspec
21
+ - lib/colorutils.rb
22
+ homepage:
23
+ licenses:
24
+ - MIT
25
+ metadata:
26
+ source_code_uri: https://github.com/nakilon/colorutils
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.5.2.3
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Common methods to work with colors.
47
+ test_files: []