01: /*
02: * Apollo - Motion capture and animation system
03: * Copyright (c) 2005 Apollo
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * as published by the Free Software Foundation; either version 2
08: * of the License, or (at your option) any later version.
09: *
10: * This program is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: * GNU General Public License for more details.
14: *
15: * You should have received a copy of the GNU General Public License
16: * along with this program; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18: *
19: * http://www.gnu.org/copyleft/gpl.html
20: *
21: * @author Giovane.Kuhn - brain@netuno.com.br
22: *
23: */
24: package org.apollo;
25:
26: import java.awt.Color;
27: import java.util.HashSet;
28: import java.util.Set;
29:
30: /**
31: * Class to generate colors
32: * @author Giovane.Kuhn on 27/05/2005
33: */
34: public final class ColorGenerator {
35:
36: public static final Color[] REJECT_CLASSIC = new Color[] { //
37: Color.BLACK, Color.WHITE, Color.RED, Color.GREEN, Color.BLUE //
38: };
39:
40: /** Seed to generate */
41: private final float seed;
42:
43: /** Indicates components min e max */
44: private final float min, max;
45:
46: /** Colors to reject */
47: private final Set<Color> reject;
48:
49: /** Actual color compoments */
50: private final float[] components;
51:
52: public ColorGenerator(float min, float max, float seed,
53: Color[] reject) {
54: this .seed = seed;
55: this .min = min;
56: this .max = max;
57: this .reject = new HashSet<Color>();
58: this .components = new float[] { min, min, min };
59: if (reject != null) {
60: for (int i = 0; i < reject.length; i++) {
61: this .reject.add(reject[i]);
62: }
63: }
64: }
65:
66: /** Restart components */
67: public void reset() {
68: for (int i = 0; i < components.length; i++) {
69: components[i] = min;
70: }
71: }
72:
73: /** Next color to be generated */
74: public Color next() {
75: Color ret;
76: while (true) {
77: ret = new Color((int) components[0], (int) components[1],
78: (int) components[2], 255);
79: reval();
80: if (!reject.contains(ret)) {
81: return ret;
82: }
83: }
84: }
85:
86: /** Reval component values */
87: private void reval() {
88: for (int i = 0; i < components.length; i++) {
89: components[i] = components[i] + seed;
90: if (components[i] < max) {
91: return;
92: }
93: components[i] = min;
94: }
95: }
96: }
|