immosquare-colors 0.1.3 → 0.1.5
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 +34 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 731aff145269af33588fd72b5abef8720b45cb260de44d9083a4f8c1417b86de
|
4
|
+
data.tar.gz: 35a426a289463a8c93d326c548217107e9e1932dc068be64d50d35bc8135e548
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71b29cc00937ae63c5b228c65e0e1461ee3f784c545b6f2b326b792f897584ba2e54d04076949fdcc457ac6e8bec388deefa2532c13f5febba1302f45e23ea15
|
7
|
+
data.tar.gz: 2d25bf197fbf33ef50b67f5ebddf84e7c6a5a2fa036478fd7b26d7db52d1b7843dd6d2e6847c1fcc3e045f39481a3a9538804ed580fbab0ced0258a833c9efe3
|
data/lib/immosquare-colors.rb
CHANGED
@@ -46,6 +46,16 @@ module ImmosquareColors
|
|
46
46
|
rgba
|
47
47
|
end
|
48
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
|
+
|
49
59
|
##============================================================##
|
50
60
|
## A dictionary for mapping textual colors to colors
|
51
61
|
## hex
|
@@ -54,5 +64,29 @@ module ImmosquareColors
|
|
54
64
|
ImmosquareConstants::Color.color_name_to_hex(color_name.downcase.to_sym) || "#000000"
|
55
65
|
end
|
56
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 = (((1 - weight) * r) + (weight * 255)).round
|
74
|
+
tinted_g = (((1 - weight) * g) + (weight * 255)).round
|
75
|
+
tinted_b = (((1 - weight) * b) + (weight * 255)).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 * (1 - weight)).round
|
86
|
+
shaded_g = (g * (1 - weight)).round
|
87
|
+
shaded_b = (b * (1 - weight)).round
|
88
|
+
rgba_to_hex([shaded_r, shaded_g, shaded_b, a])
|
89
|
+
end
|
90
|
+
|
57
91
|
end
|
58
92
|
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.5
|
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-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: immosquare-constants
|