From f92dcfbbce3d2057e39314312deed941c22881f5 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 2 Jun 2015 09:41:17 +0200 Subject: Start week15 --- Week15 Mandelbrot/src/mandelbrot/RGBColors.java | 82 +++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Week15 Mandelbrot/src/mandelbrot/RGBColors.java (limited to 'Week15 Mandelbrot/src/mandelbrot/RGBColors.java') 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]; + } +} -- cgit v1.2.3