diff options
author | Camil Staps | 2015-06-02 09:41:17 +0200 |
---|---|---|
committer | Camil Staps | 2015-06-02 09:41:17 +0200 |
commit | f92dcfbbce3d2057e39314312deed941c22881f5 (patch) | |
tree | 22b45e41686a10be4f2e87e5be752514dec5acf4 /Week15 Mandelbrot/src/mandelbrot/RGBColors.java | |
parent | week 14 tarball (diff) |
Start week15
Diffstat (limited to 'Week15 Mandelbrot/src/mandelbrot/RGBColors.java')
-rw-r--r-- | Week15 Mandelbrot/src/mandelbrot/RGBColors.java | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/Week15 Mandelbrot/src/mandelbrot/RGBColors.java b/Week15 Mandelbrot/src/mandelbrot/RGBColors.java new file mode 100644 index 0000000..2abd7d5 --- /dev/null +++ b/Week15 Mandelbrot/src/mandelbrot/RGBColors.java @@ -0,0 +1,82 @@ +/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package mandelbrot;
+
+/**
+ *
+ * @author Sjaak
+ */
+public class RGBColors {
+
+ private int [][] rgbColors;
+
+ public static final int [] BLACK = new int [3];
+
+ public RGBColors (int max_color_index) {
+ rgbColors = new int [max_color_index][3];
+ randomPalets ();
+ randomColorSet ();
+
+ }
+
+ private static final int MAXRGB = 256;
+
+ private static int [][][] palets = {
+ {{0,0},{1,-1},{0,1}},
+ {{1,-1},{1,0},{0,0}},
+ {{0,1},{0,1},{1,-1}},
+ {{1,-1},{0,0},{1,0}},
+ {{0,1},{0,1},{1,0}},
+ {{1,0},{1,-1},{1,-1}},
+ {{1,0},{0,1},{0,1}},
+ {{1,-1},{1,0},{1,-1}}
+ };
+
+ private boolean randomBool () {
+ return Math.random() < 0.5;
+ }
+
+ void randomPalets () {
+ for (int p = 0; p < palets.length; p++) {
+ for (int c = 0; c < 3; c++) {
+ int cw = randomBool () ? 1 : 0;
+ int cd = randomBool () ? (cw * -1) : (1 - cw);
+ palets [p][c][0] = cw;
+ palets [p][c][1] = cd;
+ }
+ }
+ }
+
+ private void randomColorSet () {
+ int p_size = rgbColors.length / palets.length;
+ for (int p = 0; p < palets.length; p++) {
+ int [][] palet = palets [p];
+ int r = palet [0][0] == 1 ? MAXRGB-1 : 0;
+ int g = palet [1][0] == 1 ? MAXRGB-1 : 0;
+ int b = palet [2][0] == 1 ? MAXRGB-1 : 0;
+
+ int dr = palet [0][1] * MAXRGB / p_size;
+ int dg = palet [1][1] * MAXRGB / p_size;
+ int db = palet [2][1] * MAXRGB / p_size;
+
+ for (int i = 0 ; i < p_size ; i++) {
+ rgbColors[i + p * p_size][0] = r;
+ rgbColors[i + p * p_size][1] = g;
+ rgbColors[i + p * p_size][2] = b;
+ r += dr;
+ g += dg;
+ b += db;
+ }
+ }
+ }
+
+ public int [] getColor (int color_index) {
+ return rgbColors [color_index];
+ }
+
+ public int [] getColor2 (int color_index) {
+ return rgbColors [color_index];
+ }
+}
|