colorGradient function

List<Color> colorGradient(
  1. List<Color> referenceColors,
  2. int outputLength
)

Implementation

List<Color> colorGradient(List<Color> referenceColors, int outputLength) {
  if (outputLength == 0) {
    return [];
  }

  var alphas =
      linspace(start: 0, end: referenceColors.length - 1, count: outputLength)
          .getColumn(0);

  var floors = [for (var a in alphas) a.floor()];
  var mod1 = [for (var a in alphas) a % 1];

  mod1.last = 1;
  floors.last = referenceColors.length - 2;

  return [
    for (var k in IterableZip([floors, mod1]))
      interpolate(referenceColors[k.first.toInt()],
          referenceColors[k.first.toInt() + 1], k.last.toDouble())
  ];
}