/* Copyright 1996 Matthew Freedman and University of Washington mattf@cac.washington.edu This program may be freely used, modified, or redistributed for any non-commercial purpose as long as credit is given. This file contains the ColorRandomizer class for picking new colors. */ import java.awt.*; import java.util.*; /* Tiny class for generating new random colors. Public methods are: void setSeed(int): Put a new seed in the random number generator. Color getOne(boolean white_bg): Get a new color. Pass in a flag to indicated whether the color is going to be used on a white background. */ class ColorRandomizer { private Random randy = new Random(); public void setSeed(int seed) { randy.setSeed(randy.nextLong() + (long) seed); } /* Generate a new random color. Always keep the brightness above 75%. If the background is white, keep the color completely saturated. */ public Color getOne(boolean white_bg) { return(Color.getHSBColor(randy.nextFloat(), white_bg ? 1.0f : randy.nextFloat(), (float)(randy.nextFloat()/4.0 + 0.75))); } }