immosquare-colors 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/immosquare-colors/version.rb +1 -1
- data/lib/immosquare-colors.rb +37 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cbf0b379ceb6c02f6fc3bbb88af75d8126dd4ec39e5fc914ae8f3190ddc13fe
|
4
|
+
data.tar.gz: 80f30f8b836f980bd51507fac5f36c0827a58573b203763fb529cc39c4cd83ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b7c2adde7ce4e8ab02fc2f16d68c8e12a05d083ca86e69f053df67b8f307eb3d3259e9f6b885b2965100001609cccbc3dbce55e3ed1f309b35a3cf18d719b0d
|
7
|
+
data.tar.gz: e29b267546d7626db55ec38c7a638ff86d56c6e729e736627762472aa2ee32dcf326294ed7581240323fa5a99fe6282b92fd8b235f5141b38d4d812b5ace78e3
|
data/lib/immosquare-colors.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "immosquare-constants"
|
2
|
+
|
1
3
|
module ImmosquareColors
|
2
4
|
class << self
|
3
5
|
|
@@ -44,12 +46,46 @@ module ImmosquareColors
|
|
44
46
|
rgba
|
45
47
|
end
|
46
48
|
|
49
|
+
##============================================================##
|
50
|
+
## To transform a rgba color (array) to hex
|
51
|
+
##============================================================##
|
52
|
+
def rgba_to_hex(rgba_color)
|
53
|
+
r, g, b, a = rgba_color
|
54
|
+
hex_string = format("#%02x%02x%02x", r, g, b)
|
55
|
+
hex_string += format("%02x", (a * 255).floor) if a && a != 1.0
|
56
|
+
hex_string.upcase
|
57
|
+
end
|
58
|
+
|
47
59
|
##============================================================##
|
48
60
|
## A dictionary for mapping textual colors to colors
|
49
61
|
## hex
|
50
62
|
##============================================================##
|
51
63
|
def color_name_to_hex(color_name)
|
52
|
-
|
64
|
+
ImmosquareConstants::Color.color_name_to_hex(color_name.downcase.to_sym) || "#000000"
|
65
|
+
end
|
66
|
+
|
67
|
+
##============================================================##
|
68
|
+
## Mix color whith white (255, 255, 255)
|
69
|
+
##============================================================##
|
70
|
+
def tint_color(color, weight)
|
71
|
+
color_hex = color.start_with?("#") ? color : color_name_to_hex(color)
|
72
|
+
r, g, b, a = hex_to_rgba(color_hex)
|
73
|
+
tinted_r = ((((100 - weight) * r) + (weight * 255)) / 100).round
|
74
|
+
tinted_g = ((((100 - weight) * g) + (weight * 255)) / 100).round
|
75
|
+
tinted_b = ((((100 - weight) * b) + (weight * 255)) / 100).round
|
76
|
+
rgba_to_hex([tinted_r, tinted_g, tinted_b, a])
|
77
|
+
end
|
78
|
+
|
79
|
+
##============================================================##
|
80
|
+
## Mix color whith black (0, 0, 0)
|
81
|
+
##============================================================##
|
82
|
+
def shade_color(color, weight)
|
83
|
+
color_hex = color.start_with?("#") ? color : color_name_to_hex(color)
|
84
|
+
r, g, b, a = hex_to_rgba(color_hex)
|
85
|
+
shaded_r = ((r * (100 - weight)).round / 100)
|
86
|
+
shaded_g = ((g * (100 - weight)).round / 100)
|
87
|
+
shaded_b = ((b * (100 - weight)).round / 100)
|
88
|
+
rgba_to_hex([shaded_r, shaded_g, shaded_b, a])
|
53
89
|
end
|
54
90
|
|
55
91
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: immosquare-colors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- IMMO SQUARE
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-10-
|
11
|
+
date: 2023-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: immosquare-constants
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '0'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.1.
|
22
|
+
version: 0.1.3
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '0'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.1.
|
32
|
+
version: 0.1.3
|
33
33
|
description: Provides methods to suggest complementary colors based on luminance,
|
34
34
|
convert HEX to RGBA, and map named colors to HEX
|
35
35
|
email:
|