Skip to content

Commit 2c74086

Browse files
committed
Updated Readme
1 parent 7e943a4 commit 2c74086

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

Readme.md

+39-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A Scala library for color math.
55

66
## Project goals
77

8-
ColorLib is an extension of [VecMatLib](https://github.com/HexagonNico/VecMatLib) for color math, since colors can be seen as 3D or 4D vectors whose components are the *r*, *g*, *b*, and *alpha* components of the color.
8+
ColorLib is an extension of [VecMatLib](https://github.com/ScalaMath/VecMatLib) for color math, since colors can be seen as 3D or 4D vectors whose components are the *r*, *g*, *b*, and *alpha* components of the color.
99

1010
Color classes are written in Scala to make the best use possible of Scala's operator overloading.
1111
All methods with symbolic names have an alias for better interoperability with java.
@@ -14,11 +14,11 @@ All operations in ColorLib are designed to **not** modify the object on which th
1414

1515
## Representation of colors
1616

17-
ColorLib offers 3 different representation of colors:
17+
ColorLib offers 3 different representations of colors:
1818

1919
* The `Col3f` class represents a color using three single-precision floating point numbers, representing the color's *r*, *g*, and *b* components in a range between `0.0` and `1.0`.
2020
* The `Col4f` class represents a color using four single-precision floating point numbers, representing the color's *r*, *g*, *b*, and *alpha* components in a range between `0.0` and `1.0`.
21-
* The `Col1i` class represents a color using a single 4-bits integer.
21+
* The `Col1i` class represents a color using a single 4-bytes integer.
2222

2323
The `Col3f` and `Col4f` also allow values outside the `[0.0, 1.0]` range.
2424
This representation matches the one used in the [OpenGL Shading Language](https://www.khronos.org/opengl/wiki/Data_Type_(GLSL)).
@@ -58,6 +58,39 @@ val purple = Col3f(0xff00ff) // Equivalent to (1.0f, 0.0f, 1.0f)
5858
val transparentGreen = Col4f(0x00ff0080) // Equivalent to (0.0f, 1.0f, 0.0f, 0.5f)
5959
```
6060

61+
## Gradients
62+
63+
ColorLib also contains a `Gradient` class that allows to create color gradients.
64+
A gradient is represented by a set of points, each of which is a pair made of a color and an offset.
65+
66+
```scala
67+
val gradient = Gradient(
68+
0.0f -> Col4f(1.0f, 0.0f, 0.0f), // Red
69+
0.5f -> Col4f(1.0f, 1.0f, 0.0f), // Yellow
70+
1.0f -> Col4f(0.0f, 1.0f, 0.0f) // Green
71+
)
72+
```
73+
74+
```java
75+
Gradient gradient = new Gradient()
76+
.addPoint(0.0f, new Col4f(1.0f, 0.0f, 0.0f)) // Red
77+
.addPoint(0.5f, new Col4f(1.0f, 1.0f, 0.0f)) // Yellow
78+
.addPoint(1.0f, new Col4f(0.0f, 1.0f, 0.0f)); // Green
79+
```
80+
81+
Colors can be sampled from a gradient given an offset. Considering the gradient from the previous example:
82+
83+
```scala
84+
gradient.sample(0.0f) // Returns red
85+
gradient.sample(0.25f) // Returns an interpolation between red and yellow
86+
gradient.sample(0.5f) // Returns yellow
87+
gradient.sample(0.75f) // Returns an interpolation between yellow and green
88+
gradient.sample(1.0f) // Returns green
89+
```
90+
91+
Gradients, like colors, are also immutable.
92+
The methods `addPoint` and `removePoint` do not modify the original gradient, they return a new one.
93+
6194
## Using with LWJGL
6295

6396
ColorLib can be used together with [LWJGL](https://lwjgl.org) to load colors into shaders.
@@ -71,7 +104,7 @@ public void loadUniform(String name, Color color) {
71104
}
72105
```
73106

74-
Notice how the `Color` trait is used.
107+
Notice how the `Color` trait is used instead of the concrete `Col3f` or `Col4f` classes.
75108

76109
## Multithreading
77110

@@ -107,13 +140,13 @@ implementation 'io.github.scalamath:colorlib:1.0'
107140

108141
**A**: One of the design goals of ColorLib is to be usable both in Scala and Java. Support for Scala 3 in IDEs is still actively being developed, therefore a Scala 3 library may not be suitable to work with.
109142

110-
**Q**: Why is color math not included in [VecMatLib](https://github.com/HexagonNico/VecMatLib)?
143+
**Q**: Why is color math not included in [VecMatLib](https://github.com/ScalaMath/VecMatLib)?
111144

112145
**A**: Color math used to be a part of VecMatLib, although there may be applications where colors not necessary, therefore in that case one can depend on VecMatLib without having to include an unnecessary dependency for colors.
113146

114147
## Contributing
115148

116-
ColorLib was developed by a single person as an extension of [VecMatLib](https://github.com/HexagonNico/VecMatLib).
149+
ColorLib was developed by a single person as an extension of [VecMatLib](https://github.com/ScalaMath/VecMatLib).
117150

118151
Your contributions are always welcome! Please submit a pull request or open an issue if you want to contribute with bug
119152
fixes, code improvements, documentation, and better unit test coverage.

0 commit comments

Comments
 (0)