Java Random Color getRandomColour()

Here you can find the source of getRandomColour()

Description

Get a random colour from a set of a given size.

License

LGPL

Declaration

public static Color getRandomColour() 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.awt.Color;
import java.util.Random;

public class Main {
    private static Random generator = null;

    /**//  ww w . j ava 2  s.  c om
     *  Get a random colour from a set of a given size.
     */
    public static Color getRandomColour() {
        //  Same ideas as getRandomRBG, just returns a Color.
        if (generator == null) {
            generator = new Random();
        }

        float h = generator.nextFloat();
        if (h > 0.1f && h < 0.25f) {
            h -= 0.15f; // More reds, no yellows.
        }

        return Color.getHSBColor(h, 1.0F, 0.9F);
    }
}

Related

  1. getRandomColor()
  2. getRandomColor(boolean useTransparency)
  3. getRandomColor(float offset, float alpha)
  4. getRandomColor(int saturationRandom, float luminance)
  5. getRandomColorInString()
  6. getRandomHexColor()
  7. getRandomHexColor()
  8. getRandomIntColor()
  9. getRandomRgb()