我希望能够调用一个函数,该函数接受一个基础颜色并返回对应同一颜色的不同阴影的值数组。该数组可以包含hex值或rgba()值。我还希望能够输入所需阴影的数量。阴影的数量也可以用作递增阴影的度量标准。例如,如果我想让输出具有3种不同的阴影,则第1种阴影将是基准的1/3...无论数学怎么运算...此外,在某些情况下,第1个阴影可能需要100%透明,因此我想接受一个参数来设置初始Alpha值。我已经组织了我认为是该函数的基本逻辑,但其中的数学计算对我来说不太清楚。
var buildColorStops = function (baseColor,numberOfValues,initialAlpha) {
var b = baseColor;
var n = numberOfValues //expected number of colors in the output. If n was 3 results would be [light blue, blue(base), dark blue] (# or rgba will work)
var d = 1 / n; // if number of values was 5 d would represent 1/5 of the base.
var ia = initialAlpha; // some situations may require the first color to be 100% transparent
var outputArray = [];
var i = 0;
while (i < n) {
if (i == 0) {
//...math on base color & incorporate initial alpha
outputArray.push("result of math on base")
}
else {
//...math on base color by incrementing d or 1/n
outputArray.push("result of math on base")
}
}
return outputArray;
}// end of buildColorStops