From d18949b065c93f4bc878e57c718be7a5ad1f7ae9 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 29 Apr 2015 08:46:35 +0200 Subject: Simple interface working --- Week11 Mandelbrot/src/fractals/Mandelbrot.java | 39 ++------------------------ 1 file changed, 2 insertions(+), 37 deletions(-) (limited to 'Week11 Mandelbrot/src/fractals/Mandelbrot.java') diff --git a/Week11 Mandelbrot/src/fractals/Mandelbrot.java b/Week11 Mandelbrot/src/fractals/Mandelbrot.java index 74b522e..3f2aaaa 100644 --- a/Week11 Mandelbrot/src/fractals/Mandelbrot.java +++ b/Week11 Mandelbrot/src/fractals/Mandelbrot.java @@ -7,25 +7,19 @@ package fractals; */ public class Mandelbrot { - public final static int MAX_MANDEL_NUMBER = 100; // infinity will be this + 1 - public Mandelbrot() { MainWindow fractal_win = new MainWindow (); - GridFiller filler = new GridFiller (fractal_win.getGrid()); - filler.fill(); - - System.out.println(Integer.toString(mandelNumber(0,0))); } public static void main(String args[]) { Mandelbrot mandelbrot = new Mandelbrot(); } - public static int mandelNumber(double x, double y) { + public static int mandelNumber(double x, double y, int repetitions) { double x_n = x, y_n = y; int n = 0; - while (x_n * x_n + y_n * y_n <= 4 && n <= MAX_MANDEL_NUMBER) { + while (x_n * x_n + y_n * y_n <= 4 && n <= repetitions) { double new_x_n = x_n * x_n - y_n * y_n + x; y_n = 2 * x_n * y_n + y; x_n = new_x_n; @@ -34,34 +28,5 @@ public class Mandelbrot { return n; } - - private class GridFiller { - private Grid grid; // the grid to be filled - - /** - * The constructor - * @param grid to be filled - */ - public GridFiller (Grid grid) { - this.grid = grid; - } - - private final double MIN_X = -2.5, MAX_X = 2.5, MIN_Y = -2.5, MAX_Y = 2.5; - - /** - * fills the whole grid with some arbitrarily chosen color - * - */ - public void fill () { - int grid_w = grid.getWidth(), grid_h = grid.getHeight(); - for (float i = 0; i < grid_w; i++) { - for (float j = 0; j < grid_h; j++) { - int grayscale = mandelNumber(MIN_X + (i / grid_w) * (MAX_X - MIN_X), MIN_Y + (j / grid_h) * (MAX_Y - MIN_Y)) * 256 / MAX_MANDEL_NUMBER; - int[] color = {grayscale, grayscale, grayscale}; - grid.setPixel((int) i, (int) j, color); - } - } - } - } } \ No newline at end of file -- cgit v1.2.3