Skip to content

Commit 6f11368

Browse files
committed
Separate the Color and Gradient modules
1 parent 1ec1553 commit 6f11368

File tree

8 files changed

+72
-114
lines changed

8 files changed

+72
-114
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ Some of the library's features includes:
2121
- Creating gradients
2222

2323
```lua
24+
-- Accessing the modules
25+
local ColorLib = require(...)
26+
27+
local Color = ColorLib.Color
28+
local Gradient = ColorLib.Gradient
29+
2430
-- Constructors
2531
local pink = Color.fromHex("#ff69b4")
2632
local blue = Color.from("HSB", 240, 1, 1)
@@ -47,7 +53,7 @@ red:mix(aqua, 0.5, "Lab")
4753
red:mix(aqua, 0.5, "Luv")
4854

4955
-- Gradients
50-
local gradient = Color.gradientFromColors(
56+
local gradient = Gradient.fromColors(
5157
Color.named("red"),
5258
Color.named("green"),
5359
Color.named("blue")

docs/api/gradient.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313

1414
## Constructors
1515

16-
### Color.gradient
16+
### Gradient.new
1717

1818
<img src="https://img.shields.io/badge/-static-blue" alt="Static function" />
1919

2020
```
21-
Color.gradient(keypoints: array<GradientKeypoint>): Gradient
21+
Gradient.new(keypoints: array<GradientKeypoint>): Gradient
2222
```
2323

2424
Standard Gradient constructor. The first keypoint must have a `Time` of 0, and the last keypoint must have a `Time` of 1. (Consequently, there must be at least 2 keypoints.) The keypoint list must be sorted by time.
@@ -28,24 +28,24 @@ Standard Gradient constructor. The first keypoint must have a `Time` of 0, and t
2828

2929
---
3030

31-
### Color.gradientFromColors
31+
### Gradient.fromColors
3232

3333
<img src="https://img.shields.io/badge/-static-blue" alt="Static function" />
3434

3535
```
36-
Color.gradientFromColors(...: Color): Gradient
36+
Gradient.fromColors(...: Color): Gradient
3737
```
3838

3939
Creates a Gradient from one or more Colors. If one Color is passed, the start and end keypoints will have the same color. If two Colors are passed, the start and end keypoints will have the first and second color, respectively. If 3 or more Colors is passed, the keypoints will be equidistant with respect to time.
4040

4141
---
4242

43-
### Color.gradientFromColorSequence
43+
### Gradient.fromColorSequence
4444

4545
<img src="https://img.shields.io/badge/-static-blue" alt="Static function" />
4646

4747
```
48-
Color.gradientFromColorSequence(colorSequence: ColorSequence): Gradient
48+
Gradient.fromColorSequence(colorSequence: ColorSequence): Gradient
4949
```
5050

5151
Creates a Gradient from a [ColorSequence](https://developer.roblox.com/en-us/api-reference/datatype/ColorSequence).
@@ -114,17 +114,17 @@ Returns a [ColorSequence](https://developer.roblox.com/en-us/api-reference/datat
114114
Comparing Gradients with `==` checks if they have the same number of keypoints, that the keypoints have the same Time values, and that the keypoints have the same Color values (using [Color.unclippedEq](../color/#colorunclippedeq)).
115115

116116
```lua
117-
local gradient1 = Color.gradientFromColors(
117+
local gradient1 = Gradient.fromColors(
118118
Color.new(0, 0, 0),
119119
Color.new(1, 1, 1)
120120
)
121121

122-
local gradient2 = Color.gradient({
122+
local gradient2 = Gradient.new({
123123
{Time = 0, Color = Color.new(0, 0, 0)},
124124
{Time = 1, Color = Color.new(1, 1, 1)}
125125
})
126126

127-
local gradient3 = Color.gradient({
127+
local gradient3 = Gradient.new({
128128
{Time = 0, Color = Color.new(1, 1, 1)},
129129
{Time = 1, Color = Color.new(0, 0, 0)}
130130
})

docs/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
- Documentation now reflects that the Hue component for some color types can be NaN
2121
- Static functions in the documentation now have a badge
2222
- Read-only properties in the documentation now have a badge
23+
- The Color and Gradient modules of the library are now split apart
24+
- You can access the modules using `[Module].Color` and `[Module].Gradient`
2325
- Updated the allowed interpolations for `Color.mix`
2426
- `Color.components` now allows you to obtain unclipped components
2527
- `Color.luminance` now corrects the [error](https://www.w3.org/WAI/GL/wiki/index.php?title=Relative_luminance&oldid=11187) from the equation provided in WCAG 2

docs/index.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ The module is available in the library [here](https://roblox.com/library/7933448
88

99
If you know how to use [Rojo](https://rojo.space), you can build the latest code from the development branch to get the newest features. Keep in mind that this is **development code**, and things can break or change quickly.
1010

11+
The library has two parts: the Color module and the Gradient module. You can access them using `[Module].Color` and `[Module].Gradient`.
12+
13+
```lua
14+
local ColorLib = require(...)
15+
16+
local Color = ColorLib.Color
17+
local Gradient = ColorLib.Gradient
18+
```
19+
1120
## Conversions
1221

1322
Colors can be constructed from different [color types](api/color/#color-types), including hex strings, HSB/L, and L\*a\*b\*. You can use [`Color.from`](api/color/#colorfrom) or `Color.from[ColorType]` (e.g. `Color.fromHex`).
@@ -90,7 +99,7 @@ There are also functions that don't fall into a general category:
9099

91100
Gradients are similar in construction and behaviour to ColorSequences. They can be used to generate intermediate colors or ColorSequences so that they can be used in places where they're required, such as ParticleEmitters or UIGradients.
92101

93-
A Gradient can be constructed using an array of "gradient keypoints", which is just a dictionary with a `Time` and `Color` field, similar to the `Time` and `Value` fields of a [ColorSequenceKeypoint](https://developer.roblox.com/api-reference/datatype/ColorSequenceKeypoint). The constructor for this method is [`Color.gradient`](api/gradient/#colorgradient).
102+
A Gradient can be constructed using an array of "gradient keypoints", which is just a dictionary with a `Time` and `Color` field, similar to the `Time` and `Value` fields of a [ColorSequenceKeypoint](https://developer.roblox.com/api-reference/datatype/ColorSequenceKeypoint). The constructor for this method is [`Gradient.new`](api/gradient/#gradientnew).
94103

95104
```lua
96105
local keypoints = {
@@ -99,34 +108,34 @@ local keypoints = {
99108
{Time = 1, Color = Color.grey(1)}
100109
}
101110

102-
local gradient = Color.gradient(keypoints)
111+
local gradient = Gradient.new(keypoints)
103112
```
104113

105-
You can also construct a Gradient with a list of Colors using [`Color.gradientFromColors`](api/gradient/#colorgradientfromcolors). This creates a gradient where the colors are equidistant from each other.
114+
You can also construct a Gradient with a list of Colors using [`Gradient.fromColors`](api/gradient/#gradientfromcolors). This creates a gradient where the colors are equidistant from each other.
106115

107116
```lua
108-
local gradient = Color.gradientFromColors(
117+
local gradient = Gradient.fromColors(
109118
Color.named("red"),
110119
Color.named("green"),
111120
Color.named("blue")
112121
)
113122
```
114123

115-
Finally, the constructor [`Color.gradientFromColorSequence`](api/gradient/#colorgradientfromcolorsequence) creates a gradient from a ColorSequence.
124+
Finally, the constructor [`Gradient.fromColorSequence`](api/gradient/#gradientfromcolorsequence) creates a gradient from a ColorSequence.
116125

117126
```lua
118127
local cs = ColorSequence.new(
119128
Color3.new(0, 0, 0),
120129
Color3.new(1, 1, 1)
121130
)
122131

123-
local gradient = Color.gradientFromColorSequence(cs)
132+
local gradient = Gradient.fromColorSequence(cs)
124133
```
125134

126135
Generating colors from a gradient is similar to mixing colors, using [`Gradient.color`](api/gradient/#gradientcolor). If you need a list of colors, you can use [`Gradient.colors`](api/gradient/#gradientcolors). If you need a ColorSequence, you can use [`Gradient.colorSequence`](api/gradient/#gradientcolorsequence).
127136

128137
```lua
129-
local gradient = Color.gradientFromColors(
138+
local gradient = Gradient.fromColors(
130139
Color.named("red"),
131140
Color.named("green"),
132141
Color.named("blue")

src/init.lua

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -10,73 +10,6 @@ export type GradientKeypoint = Gradient.GradientKeypoint
1010
---
1111

1212
return {
13-
new = Color.new,
14-
random = Color.random,
15-
gray = Color.gray,
16-
named = Color.named,
17-
from = Color.from,
18-
19-
isAColor = Color.isAColor,
20-
isClipped = Color.isClipped,
21-
unclippedEq = Color.unclippedEq,
22-
23-
components = Color.components,
24-
to = Color.to,
25-
26-
invert = Color.invert,
27-
mix = Color.mix,
28-
blend = Color.blend,
29-
30-
deltaE = Color.deltaE,
31-
luminance = Color.luminance,
32-
contrast = Color.contrast,
33-
bestContrastingColor = Color.bestContrastingColor,
34-
35-
brighten = Color.brighten,
36-
darken = Color.darken,
37-
saturate = Color.saturate,
38-
desaturate = Color.desaturate,
39-
harmonies = Color.harmonies,
40-
41-
gradient = Gradient.new,
42-
gradientFromColors = Gradient.fromColors,
43-
gradientFromColorSequence = Gradient.fromColorSequence,
44-
45-
fromBrickColor = Color.fromBrickColor,
46-
fromCMYK = Color.fromCMYK,
47-
fromColor3 = Color.fromColor3,
48-
fromHex = Color.fromHex,
49-
fromHSB = Color.fromHSB,
50-
fromHSL = Color.fromHSL,
51-
fromHWB = Color.fromHWB,
52-
fromLab = Color.fromLab,
53-
fromLChab = Color.fromLChab,
54-
fromLChuv = Color.fromLChuv,
55-
fromLuv = Color.fromLuv,
56-
fromNumber = Color.fromNumber,
57-
fromRGB = Color.fromRGB,
58-
fromTemperature = Color.fromTemperature,
59-
fromXYZ = Color.fromXYZ,
60-
61-
toBrickColor = Color.toBrickColor,
62-
toCMYK = Color.toCMYK,
63-
toColor3 = Color.toColor3,
64-
toHex = Color.toHex,
65-
toHSB = Color.toHSB,
66-
toHSL = Color.toHSL,
67-
toHWB = Color.toHWB,
68-
toLab = Color.toLab,
69-
toLChab = Color.toLChab,
70-
toLChuv = Color.toLChuv,
71-
toLuv = Color.toLuv,
72-
toNumber = Color.toNumber,
73-
toRGB = Color.toRGB,
74-
toTemperature = Color.toTemperature,
75-
toXYZ = Color.toXYZ,
76-
77-
fromHSV = Color.fromHSV,
78-
fromLCh = Color.fromLCh,
79-
80-
toHSV = Color.toHSV,
81-
toLCh = Color.toLCh,
13+
Color = Color,
14+
Gradient = Gradient,
8215
}

tests/Color.spec.lua

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,43 @@
11
return function()
2-
local Color = require(game:GetService("ReplicatedStorage").Color.Color)
2+
local ColorLib = require(game:GetService("ReplicatedStorage"):FindFirstChild("Color"))
3+
local Color = ColorLib.Color
34

45
it("should be immutable", function()
56
expect(function()
67
Color.new = nil
78
end).to.throw()
89
end)
910

11+
it("should have a public API", function()
12+
expect(Color.isAColor).to.be.a("function")
13+
expect(Color.isClipped).to.be.a("function")
14+
15+
expect(Color.new).to.be.a("function")
16+
expect(Color.random).to.be.a("function")
17+
expect(Color.gray).to.be.a("function")
18+
expect(Color.named).to.be.a("function")
19+
expect(Color.from).to.be.a("function")
20+
21+
expect(Color.unclippedEq).to.be.a("function")
22+
expect(Color.components).to.be.a("function")
23+
expect(Color.to).to.be.a("function")
24+
25+
expect(Color.invert).to.be.a("function")
26+
expect(Color.mix).to.be.a("function")
27+
expect(Color.blend).to.be.a("function")
28+
29+
expect(Color.deltaE).to.be.a("function")
30+
expect(Color.luminance).to.be.a("function")
31+
expect(Color.contrast).to.be.a("function")
32+
expect(Color.bestContrastingColor).to.be.a("function")
33+
34+
expect(Color.brighten).to.be.a("function")
35+
expect(Color.darken).to.be.a("function")
36+
expect(Color.saturate).to.be.a("function")
37+
expect(Color.desaturate).to.be.a("function")
38+
expect(Color.harmonies).to.be.a("function")
39+
end)
40+
1041
it("should have alternative construction functions", function()
1142
expect(Color.fromBrickColor).to.be.a("function")
1243
expect(Color.fromCMYK).to.be.a("function")

tests/Gradient.spec.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
local ColorModule = game:GetService("ReplicatedStorage").Color
2-
31
return function()
4-
local Color = require(ColorModule.Color)
5-
local Gradient = require(ColorModule.Gradient)
2+
local ColorLib = require(game:GetService("ReplicatedStorage"):FindFirstChild("Color"))
3+
4+
local Color = ColorLib.Color
5+
local Gradient = ColorLib.Gradient
66

77
it("should be immutable", function()
88
expect(function()

tests/init.spec.lua

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)