getGradientInBetween static method
List<GuiGradientColor>
getGradientInBetween(
- double stop,
- List<
GuiGradientColor> fromGradient, - double fromStop,
- List<
GuiGradientColor> toGradient, - double toStop,
Generate a gradient in between two other gradients, where stop is a value in between fromStop to toStop.
The gradient colors are interpolated from fromGradient and toGradient.
Implementation
static List<GuiGradientColor> getGradientInBetween(
double stop,
List<GuiGradientColor> fromGradient,
double fromStop,
List<GuiGradientColor> toGradient,
double toStop) {
// fromgrad and tograd must have the same number of elements (as achieved after normalizing each gradient to have all stops)
List<GuiGradientColor> gradient = <GuiGradientColor>[];
if (stop == fromStop) return fromGradient;
if (stop == toStop || fromStop == toStop) return toGradient;
// else compute gradient based on location of stop between fromStop and toStop.
double t = (stop - fromStop) / (toStop - fromStop);
for (int i = 0; i < fromGradient.length; i++) {
gradient.add(GuiGradientColor(
Color.lerp(fromGradient[i].color, toGradient[i].color, t)!,
fromGradient[i].stop));
}
return gradient;
}