@quenty/color3utils 2.0.0 → 2.0.1
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.
- package/CHANGELOG.md +8 -0
- package/LICENSE.md +1 -1
- package/README.md +6 -24
- package/package.json +2 -2
- package/src/Shared/Color3Utils.lua +53 -12
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.0.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/color3utils@2.0.0...@quenty/color3utils@2.0.1) (2021-12-30)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @quenty/color3utils
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [2.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/color3utils@1.2.0...@quenty/color3utils@2.0.0) (2021-09-05)
|
|
7
15
|
|
|
8
16
|
|
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
## Color3Utils
|
|
2
2
|
<div align="center">
|
|
3
|
-
<a href="http://quenty.github.io/
|
|
4
|
-
<img src="https://
|
|
3
|
+
<a href="http://quenty.github.io/NevermoreEngine/">
|
|
4
|
+
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/docs.yml/badge.svg" alt="Documentation status" />
|
|
5
5
|
</a>
|
|
6
6
|
<a href="https://discord.gg/mhtGUS8">
|
|
7
|
-
<img src="https://img.shields.io/
|
|
7
|
+
<img src="https://img.shields.io/discord/385151591524597761?color=5865F2&label=discord&logo=discord&logoColor=white" alt="Discord" />
|
|
8
8
|
</a>
|
|
9
9
|
<a href="https://github.com/Quenty/NevermoreEngine/actions">
|
|
10
10
|
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg" alt="Build and release status" />
|
|
@@ -13,27 +13,9 @@
|
|
|
13
13
|
|
|
14
14
|
Utility methods for Roblox Color3 values
|
|
15
15
|
|
|
16
|
+
<div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/Color3Utils">View docs →</a></div>
|
|
17
|
+
|
|
16
18
|
## Installation
|
|
17
19
|
```
|
|
18
20
|
npm install @quenty/color3utils --save
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Usage
|
|
22
|
-
Usage is designed to be simple.
|
|
23
|
-
|
|
24
|
-
### `Color3Utils.getRelativeLuminance(color)`
|
|
25
|
-
Luminance as per W3 per sRGB colorspace normalized with 0
|
|
26
|
-
|
|
27
|
-
### `Color3Utils.textShouldBeBlack(color)`
|
|
28
|
-
Returns whether or not the text should be black using
|
|
29
|
-
|
|
30
|
-
### `Color3Utils.scaleValue(color3, percent)`
|
|
31
|
-
|
|
32
|
-
### `Color3Utils.setValue(color3, value)`
|
|
33
|
-
|
|
34
|
-
### `Color3Utils.setHue(color3, hue)`
|
|
35
|
-
|
|
36
|
-
### `Color3Utils.scaleSaturation(color3, percent)`
|
|
37
|
-
|
|
38
|
-
### `Color3Utils.setSaturation(color3, saturation)`
|
|
39
|
-
|
|
21
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/color3utils",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Utility methods for Roblox Color3 values",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "d146c77d0a8e452824de0ab0b4b03ba0370bcc1b"
|
|
31
31
|
}
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
--[=[
|
|
2
|
+
Utility methods for Roblox Color3 values
|
|
3
|
+
@class Color3Utils
|
|
4
|
+
]=]
|
|
3
5
|
|
|
4
6
|
local Color3Utils = {}
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
--[=[
|
|
9
|
+
Luminance as per W3 per sRGB colorspace normalized with 0
|
|
10
|
+
as the darkest dark, and 1 as the whitest white.
|
|
11
|
+
|
|
12
|
+
See https://www.w3.org/TR/WCAG20/#relativeluminancedef
|
|
13
|
+
|
|
14
|
+
@param color Color3 -- The Color3 to check
|
|
15
|
+
@return number -- A scalar from 0 to 1 with 0 as the darkest dark, and 1 as the whitest white
|
|
16
|
+
|
|
17
|
+
]=]
|
|
11
18
|
function Color3Utils.getRelativeLuminance(color)
|
|
12
19
|
local components = { color.r, color.g, color.b }
|
|
13
20
|
local vals = {}
|
|
@@ -22,35 +29,69 @@ function Color3Utils.getRelativeLuminance(color)
|
|
|
22
29
|
return 0.2126 * vals[1] + 0.7152 * vals[2] + 0.0722 * vals[3]
|
|
23
30
|
end
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
--[=[
|
|
33
|
+
Returns whether or not the text should be black using
|
|
34
|
+
relative luminance as a metric.
|
|
35
|
+
|
|
36
|
+
See https://stackoverflow.com/questions/3942878/
|
|
37
|
+
|
|
38
|
+
@param color Color3 -- The Color3 to check
|
|
39
|
+
@return boolean -- True if the text should be black, false if it should be good
|
|
40
|
+
]=]
|
|
30
41
|
function Color3Utils.textShouldBeBlack(color)
|
|
31
42
|
return Color3Utils.getRelativeLuminance(color) > 0.179
|
|
32
43
|
end
|
|
33
44
|
|
|
45
|
+
--[=[
|
|
46
|
+
Scales the value component of hsv
|
|
47
|
+
@param color3 Color3
|
|
48
|
+
@param percent number -- Percent scaling
|
|
49
|
+
@return Color3
|
|
50
|
+
]=]
|
|
34
51
|
function Color3Utils.scaleValue(color3, percent)
|
|
35
52
|
local h, s, v = Color3.toHSV(color3)
|
|
36
53
|
return Color3.fromHSV(h, s, percent*v)
|
|
37
54
|
end
|
|
38
55
|
|
|
56
|
+
--[=[
|
|
57
|
+
Sets the value component of hsv
|
|
58
|
+
@param color3 Color3
|
|
59
|
+
@param value number
|
|
60
|
+
@return Color3
|
|
61
|
+
]=]
|
|
39
62
|
function Color3Utils.setValue(color3, value)
|
|
40
63
|
local h, s, _ = Color3.toHSV(color3)
|
|
41
64
|
return Color3.fromHSV(h, s, value)
|
|
42
65
|
end
|
|
43
66
|
|
|
67
|
+
--[=[
|
|
68
|
+
Sets the hue component of hsv
|
|
69
|
+
@param color3 Color3
|
|
70
|
+
@param hue number
|
|
71
|
+
@return Color3
|
|
72
|
+
]=]
|
|
44
73
|
function Color3Utils.setHue(color3, hue)
|
|
45
74
|
local _, s, v = Color3.toHSV(color3)
|
|
46
75
|
return Color3.fromHSV(hue, s, v)
|
|
47
76
|
end
|
|
48
77
|
|
|
78
|
+
--[=[
|
|
79
|
+
Scales the saturation component of hsv
|
|
80
|
+
@param color3 Color3
|
|
81
|
+
@param percent number -- Percent scaling
|
|
82
|
+
@return Color3
|
|
83
|
+
]=]
|
|
49
84
|
function Color3Utils.scaleSaturation(color3, percent)
|
|
50
85
|
local h, s, v = Color3.toHSV(color3)
|
|
51
86
|
return Color3.fromHSV(h, percent*s, v)
|
|
52
87
|
end
|
|
53
88
|
|
|
89
|
+
--[=[
|
|
90
|
+
Sets the saturation component of hsv
|
|
91
|
+
@param color3 Color3
|
|
92
|
+
@param saturation number
|
|
93
|
+
@return Color3
|
|
94
|
+
]=]
|
|
54
95
|
function Color3Utils.setSaturation(color3, saturation)
|
|
55
96
|
local h, _, v = Color3.toHSV(color3)
|
|
56
97
|
return Color3.fromHSV(h, saturation, v)
|