Here you can find the source of getRandomColor(float offset, float alpha)
Parameter | Description |
---|---|
offset | the offset between 0.0 and 1.0 |
alpha | the alpha value between 0.0 and 1.0 |
public static final Color getRandomColor(float offset, float alpha)
//package com.java2s; import java.awt.Color; public class Main { /**/* w w w. j a va2 s . co m*/ * Returns a random color given the offset and alpha values. * @param offset the offset between 0.0 and 1.0 * @param alpha the alpha value between 0.0 and 1.0 * @return Color */ public static final Color getRandomColor(float offset, float alpha) { final float max = 1.0f; final float min = 0.0f; // make sure the offset is valid if (offset > max) offset = min; if (offset < min) offset = min; // use the offset to calculate the color float multiplier = max - offset; // compute the rgb values float r = (float) Math.random() * multiplier + offset; float g = (float) Math.random() * multiplier + offset; float b = (float) Math.random() * multiplier + offset; return new Color(r, g, b, alpha); } }