awaySetColor static method
让useColor
和fromColor
保持 sub
以上 的距离
Implementation
static Color awaySetColor(
Color? useColor,
Color fromColor,
int sub, {
bool toUpper = true,
}) {
if (null == useColor) {
return shiftColor(fromColor, sub);
}
int subPoint(int usePoint, int fromPoint, int limit) {
final sub = usePoint - fromPoint;
if (limit < 0) {
limit = -limit;
}
if (sub <= limit && sub >= -limit) {
if (toUpper) {
return math.min((math.max(usePoint, fromPoint) + limit), 255);
} else {
return math.max((math.min(usePoint, fromPoint) - limit), 0);
}
}
return usePoint;
}
return Color.fromRGBO(
subPoint(useColor.red, fromColor.red, sub),
subPoint(useColor.green, fromColor.green, sub),
subPoint(useColor.blue, fromColor.blue, sub),
1,
);
}