You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Readme.md
+39-6
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ A Scala library for color math.
5
5
6
6
## Project goals
7
7
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.
9
9
10
10
Color classes are written in Scala to make the best use possible of Scala's operator overloading.
11
11
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
14
14
15
15
## Representation of colors
16
16
17
-
ColorLib offers 3 different representation of colors:
17
+
ColorLib offers 3 different representations of colors:
18
18
19
19
* 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`.
20
20
* 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.
22
22
23
23
The `Col3f` and `Col4f` also allow values outside the `[0.0, 1.0]` range.
24
24
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)
58
58
valtransparentGreen=Col4f(0x00ff0080) // Equivalent to (0.0f, 1.0f, 0.0f, 0.5f)
59
59
```
60
60
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
+
valgradient=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 =newGradient()
76
+
.addPoint(0.0f, newCol4f(1.0f, 0.0f, 0.0f)) // Red
**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.
109
142
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)?
111
144
112
145
**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.
113
146
114
147
## Contributing
115
148
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).
117
150
118
151
Your contributions are always welcome! Please submit a pull request or open an issue if you want to contribute with bug
119
152
fixes, code improvements, documentation, and better unit test coverage.
0 commit comments