【发布时间】:2016-08-14 15:06:45
【问题描述】:
我想要一个静态方法,无论何时调用它都会返回一个尚未出现的颜色值,并且与上次返回的颜色不太接近(即return new Color(last_value += 10) 不会这样做)。它也不应该是随机的,因此每次启动应用程序时,返回颜色的顺序都是相同的。
我想到的第一件事是使用原始数字步长遍历数组,如下所示:
private static HashMap<Integer, Boolean> used = new HashMap<>();
private static int[] values = new int[0xfffff]; // 1/16th of possible colors
private static int current = 0, jump = values.length / 7;
public static Color getColour(){
int value = values[current];
used.put(current, true);
current += jump;
current %= values.length;
//have some check here if all colors were used
while (used.containsKey(current)){
current++;
current%=values.length;
}
return new Color(value);
}
但我不喜欢它,因为在某些回调中颜色会彼此接近。
【问题讨论】:
-
您如何准确定义 RGB 配色方案的接近度?
-
为什么不需要随机颜色?我认为在某些时候你必须使用随机。
-
@svs 好吧,只要看一眼颜色就可以彼此区分,同时由宽调色板组成,所以它不仅仅是例如。红色。
-
@Priyamal 使用的颜色是用户界面的一部分,如果用户每次启动应用程序时,一切看起来都不一样,那肯定会给用户带来困扰。
-
@CoderinoJavarino
colors are distinct from each other just by glancing at it你是如何在数学上定义的?