linearGradient function

List<List<num>> linearGradient (
  1. num n,
  2. List<num> color1,
  3. List<num> color2
)

returns an length n array of Vector3 colours. colours are evenly spaced between color1 and color2.

Implementation

List<List<num>> linearGradient(
  num n,
  List<num> color1,
  List<num> color2,
) {
  var d = (n - 1 != 0) ? n - 1 : 1;
  var result = List.generate(n, (i) => lerp3(i / d, color1, color2)).toList();
  return result;
}