2020-04-27 07:44:19 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# canvas API helper functions
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
var _getColor = func(color) {
|
|
|
|
if (size(color) == 1)
|
|
|
|
var color = color[0];
|
|
|
|
|
2020-05-05 18:13:06 +00:00
|
|
|
if (isscalar(color))
|
2020-04-27 07:44:19 +00:00
|
|
|
return color;
|
2020-05-05 18:13:06 +00:00
|
|
|
if (!isvec(color))
|
2020-04-27 07:44:19 +00:00
|
|
|
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 ~ ')';
|
|
|
|
};
|
|
|
|
|
2020-05-05 18:13:06 +00:00
|
|
|
var _arg2valarray = func {
|
2020-04-27 07:44:19 +00:00
|
|
|
var ret = arg;
|
2020-05-05 18:13:06 +00:00
|
|
|
while (isvec(ret) and size(ret) == 1 and isvec(ret[0])) {
|
2020-04-27 07:44:19 +00:00
|
|
|
ret = ret[0];
|
2020-05-05 18:13:06 +00:00
|
|
|
}
|
2020-04-27 07:44:19 +00:00
|
|
|
return ret;
|
|
|
|
}
|