blob: 064bd15f1ada035b16e7bcd83ce44943ddc281ba (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
package fractals;
import java.awt.Color;
/**
*
* @author Sjaak Smetsers
* @version 1.0. 14-03-2014
*/
/**
* Converting indexes (ranging from 0 to tableSize) to RGB colors
*
* @author Sjaak
*/
public class ColorTable {
// a two dimensional conversion array
private int[][] rgbColors;
private int tableSize;
private static final int MAXRGB = 256;
public static final int[] BLACK = new int[3];
/**
* converts specified color to an rgb array
*
* @param color the color to be converted
* @return the corresponding array of rgb values
*/
private static int[] color2RGB(Color color) {
int[] rgb = {color.getRed(), color.getGreen(), color.getBlue()};
return rgb;
}
/**
* creates and fills the table with the specified size
*
* @param tableSize the size of the table
*/
public ColorTable(int tableSize) {
this.tableSize = tableSize;
this.rgbColors = new int[tableSize][3];
randomColorSet();
}
/**
* fills the table randomly
*/
private void randomColorSet() {
for (int[] color : rgbColors) {
for (int c = 0; c < 3; c++) {
color[c] = (int) (Math.random() * 256);
}
}
}
/**
* converts an index into an rgb value
*
* @param color_index to be converted
* @return the resulting rgb value
*/
public int[] getColor(int color_index) {
return rgbColors[color_index % tableSize];
}
}
|