Loading

采用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)

posted @ 2017-01-02 15:32  辉灬  阅读(599)  评论(0编辑  收藏  举报