I forget the original author.
function getClosestPaintColor(%rgba)
{
%prevdist = 100000;
%colorMatch = 0;
for(%i = 0; %i < 64; %i++)
{
%color = getColorIDTable(%i);
if(vectorDist(%rgba,getWords(%color,0,2)) < %prevdist && getWord(%rgba,3) - getWord(%color,3) < 0.3 && getWord(%rgba,3) - getWord(%color,3) > -0.3)
{
%prevdist = vectorDist(%rgba,%color);
%colormatch = %i;
}
}
return %colormatch;
}