aboutsummaryrefslogtreecommitdiff
path: root/Week11 Mandelbrot/src/fractals/ColorTable.java
diff options
context:
space:
mode:
authorCamil Staps2015-04-28 13:36:51 +0200
committerCamil Staps2015-04-28 13:36:51 +0200
commita3c4d590c471ddf79b204c7039a597b4be264ad9 (patch)
tree800c93ba842b1e8ab64fc28b33eb5cdd8986d165 /Week11 Mandelbrot/src/fractals/ColorTable.java
parentAdded assignment week 10 (diff)
Initial commit w11
Diffstat (limited to 'Week11 Mandelbrot/src/fractals/ColorTable.java')
-rw-r--r--Week11 Mandelbrot/src/fractals/ColorTable.java69
1 files changed, 69 insertions, 0 deletions
diff --git a/Week11 Mandelbrot/src/fractals/ColorTable.java b/Week11 Mandelbrot/src/fractals/ColorTable.java
new file mode 100644
index 0000000..064bd15
--- /dev/null
+++ b/Week11 Mandelbrot/src/fractals/ColorTable.java
@@ -0,0 +1,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];
+ }
+
+}