Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #1312
| From | "John B. Matthews" <nospam@nospam.invalid> |
|---|---|
| Newsgroups | comp.lang.java.help |
| Subject | Re: Connecting colour to the ball |
| Date | 2011-11-10 01:20 -0500 |
| Organization | The Wasteland |
| Message-ID | <nospam-672201.01202810112011@news.aioe.org> (permalink) |
| References | <b46185c6-ceea-46bd-972a-3fe2dbe7767d@h5g2000yqk.googlegroups.com> <po5mb7diakn505ag05gletdg0u67nd48q8@4ax.com> |
In article <po5mb7diakn505ag05gletdg0u67nd48q8@4ax.com>,
Roedy Green <see_website@mindprod.com.invalid> wrote:
> On Wed, 9 Nov 2011 08:39:00 -0800 (PST), Michael Adedeji
> <yankosmgt@gmail.com> wrote, quoted or indirectly quoted someone who
> said :
>
> > Random ran = new Random();
> > int ranInt = ran.nextInt(4);
>
> there's one bug.
>
> See http://mindprod.com/jgloss/pseudorandom.html
>
> you construct ran only once, and use nextInt in the loop
Well spotted. A nice alternative is to construct a color lookup table:
private static final float N = 64;
private final Queue<Color> clut = new LinkedList<Color>();
Fill it with a suitable gamut:
for (int i = 0; i < N; i++) {
clut.add(Color.getHSBColor(i / N, 1, 1));
}
And cycle through it:
public void paintComponent(Graphics g) {
...
g.setColor(clut.peek());
g.fillOval(...);
clut.add(clut.remove());
...
}
There's a related sscce here:
<http://stackoverflow.com/questions/2124507>
--
[Please omit signatures when responding.]
Back to comp.lang.java.help | Previous | Next — Previous in thread | Find similar
Connecting colour to the ball Michael Adedeji <yankosmgt@gmail.com> - 2011-11-09 08:39 -0800
Re: Connecting colour to the ball Roedy Green <see_website@mindprod.com.invalid> - 2011-11-09 16:13 -0800
Re: Connecting colour to the ball "John B. Matthews" <nospam@nospam.invalid> - 2011-11-10 01:20 -0500
csiph-web