35 lines
984 B
Text
35 lines
984 B
Text
|
#-------------------------------------------------------------------------------
|
||
|
# 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;
|
||
|
}
|