complementary method Null safety

List<Color> complementary(
  1. int count,
  2. [double? distance]
)

The number of Colors returned in this List will match count, and the original color this will be first amongst them.

Implementation

List<Color> complementary(int count, [double? distance]) {
  double wrap(double component, double d) {
    final sum = component + d;
    if (sum >= 0 && sum <= 360) return sum;
    return sum.remainder(360);
  }

  final shift = 360 / count;
  final hsl = HSLColor.fromColor(this);
  return List<Color>.generate(
      count,
      (int i) => HSLColor.fromAHSL(
            hsl.alpha,
            wrap(hsl.hue, shift * i),
            hsl.saturation,
            hsl.lightness,
          ).toColor());
}