假设我有两种颜色。
public final static Color FAR = new Color(237, 237, 30);
public final static Color CLOSE = new Color(58, 237, 221);
如何在不浸入深色的情况下从一种颜色过渡到另一种颜色?
我想出了诸如
double ratio = diff / range; // goes from 1 to 0
int red = (int)Math.abs((ratio * FAR.getRed()) - ((1 - ratio) * CLOSE.getRed()));
int green = (int)Math.abs((ratio * FAR.getGreen()) - ((1 - ratio) * CLOSE.getGreen()));
int blue = (int)Math.abs((ratio * FAR.getBlue()) - ((1 - ratio) * CLOSE.getBlue()));
或者
double ratio = diff / range; // goes from 1 to 0
int red = (int) ((1 - (diff / range)) * FAR.getRed() + CLOSE.getRed() - FAR.getRed());
int green = (int) ((1 - (diff / range)) * FAR.getGreen() + CLOSE.getGreen() - FAR.getGreen());
int blue = (int) ((1 - (diff / range)) * FAR.getBlue() + CLOSE.getBlue() - FAR.getBlue());
但不幸的是,它们都没有从一种颜色平滑过渡到另一种颜色。有谁知道如何在保持颜色明亮而不陷入较暗颜色的同时做到这一点,或者如何确保渐变过渡是平滑的,而不是一开始就变慢,然后变快,然后又变慢?
我真的想不出任何公式。