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/ColorChooser.java | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Week15 Mandelbrot/src/mandelbrot/ColorChooser.java (limited to 'Week15 Mandelbrot/src/mandelbrot/ColorChooser.java') diff --git a/Week15 Mandelbrot/src/mandelbrot/ColorChooser.java b/Week15 Mandelbrot/src/mandelbrot/ColorChooser.java new file mode 100644 index 0000000..c3aa441 --- /dev/null +++ b/Week15 Mandelbrot/src/mandelbrot/ColorChooser.java @@ -0,0 +1,36 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package mandelbrot; + +/** + * + * @author Sjaak + */ +public class ColorChooser { + private int maxIndex; + + public ColorChooser () { + maxIndex = 0; + } + + public void setMaxIndex (int max_index) { + maxIndex = max_index; + } + + public int getColorIndex (double x0, double y0) { + double x = x0, y = y0; + int color_index = 0; + while (x * x + y * y < 4.0) { + double nx = x * x - y * y + x0; + y = 2 * x * y + y0; + x = nx; + color_index++; + if (color_index == maxIndex) { + return -1; + } + } + return color_index; + } +} -- cgit v1.2.3