采用HSV生成随机颜色

时间:2023-03-09 03:37:39
采用HSV生成随机颜色

使用hsv/hsb生成随机颜色,并排除靠近黑白两色的色值

    public static String randomColor(){
int max = 25500000 ;
Random rand = new Random();
int r = rand.nextInt(max);
int b = rand.nextInt(max);
int g = rand.nextInt(max); float h = r % 360.0f;
float s = g % 180 / 360.0f + 0.5f;
float v = b % 180 / 360.0f + 0.5f;
float[] hsv = new float[]{h,s,v}; // h- 0...360 s-0...1 v-0...1
System.out.println("颜色 : "+"h="+h+",s="+s+",v="+v + " , argb=" + Color.HSVToColor(0x88, hsv));
return Color.HSVToColor(0x88, hsv)+"";
}

注意:可直接返回整形,使用直接用setColor(int color)