Java Random Color getRandomColor(float offset, float alpha)

Here you can find the source of getRandomColor(float offset, float alpha)

Description

Returns a random color given the offset and alpha values.

License

Open Source License

Parameter

Parameter Description
offset the offset between 0.0 and 1.0
alpha the alpha value between 0.0 and 1.0

Return

Color

Declaration

public static final Color getRandomColor(float offset, float alpha) 

Method Source Code


//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);
    }
}

Related

  1. GetRandomColor()
  2. getRandomColor()
  3. getRandomColor()
  4. getRandomColor()
  5. getRandomColor(boolean useTransparency)
  6. getRandomColor(int saturationRandom, float luminance)
  7. getRandomColorInString()
  8. getRandomColour()
  9. getRandomHexColor()