1
0
Fork 0
fgdata/Nasal/canvas/api/helpers.nas

35 lines
984 B
Text
Raw Normal View History

2020-04-27 07:44:19 +00:00
#-------------------------------------------------------------------------------
# canvas API helper functions
#-------------------------------------------------------------------------------
#
var _getColor = func(color) {
if (size(color) == 1)
var color = color[0];
if (typeof(color) == "scalar")
return color;
if (typeof(color) != "vector")
return debug.warn("Wrong type for color");
if (size(color) < 3 or size(color) > 4)
return debug.warn("Color needs 3 or 4 values (RGB or RGBA)");
var str = 'rgb';
if (size(color) == 4)
str ~= 'a';
str ~= '(';
# rgb = [0,255], a = [0,1]
for (var i = 0; i < size(color); i += 1) {
str ~= (i > 0 ? ',' : '') ~ (i < 3 ? int(color[i] * 255) : color[i]);
}
return str ~ ')';
};
var _arg2valarray = func
{
var ret = arg;
while (typeof(ret) == "vector" and size(ret) == 1 and typeof(ret[0]) == "vector")
ret = ret[0];
return ret;
}