To be fair, this one does different things from mine - mine is (on purpose) only concerned with value ranges and function patching, not so much with different color representations.
In addition to ivan's remarks, I would expect that all components are to be given in the same value range. It makes little sense to me that rgb() expects r, g, b in the [0,255] range, but a has to be given in the [0.0,1.0] range. This is also true for the hex() function, which in my opinion should accept #RRGGBBAA and #RGBA strings.
hex() has a bug in its conversion code: 0xa through 0xf equals 10 through 15, not 11 through 16. Calling hex('#fff') will calculate the color from {272, 272, 272, 255}, which is obviously wrong.
It may be better for performance to return separate values instead of creating a new table in rgb() and hex().
Code: Select all
return {r/255, g/255, b/255, a} -- no
return r/255, g/255, b/255, a -- yes
It makes sense to return a table in vec4(), though you should allow the caller to provide the target table for better efficiency:
Code: Select all
function vec4 (r, g, b, a, result)
result = result or {}
...
And a useful addition would be conversion to and from the
HSV color space.