diff options
Diffstat (limited to 'Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotController.java')
| -rw-r--r-- | Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotController.java | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotController.java b/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotController.java deleted file mode 100644 index f072805..0000000 --- a/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotController.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2015 Camil Staps - */ -package com.camilstaps.mandelbrot; - -import fractals.Grid; -import fractals.Mandelbrot; - -/** - * - * @author camilstaps - */ -public class MandelbrotController { - - private final MandelbrotProvider mandelbrotProvider; - private final Grid grid; - - public MandelbrotController(MandelbrotProvider mp, Grid grid) { - mandelbrotProvider = mp; - this.grid = grid; - } - - public double getX(int x_on_screen) { - double centerX = mandelbrotProvider.getCenterX(); - double scale = mandelbrotProvider.getScale(); - int grid_w = grid.getWidth(); - double min_x = centerX - grid_w / scale / 2, - max_x = centerX + grid_w / scale / 2; - - return min_x + (((float) x_on_screen) / grid_w) * (max_x - min_x); - } - - public double getY(int y_on_screen) { - double centerY = mandelbrotProvider.getCenterY(); - double scale = mandelbrotProvider.getScale(); - int grid_h = grid.getHeight(); - double min_y = centerY - grid_h / scale / 2, - max_y = centerY + grid_h / scale / 2; - - return min_y + (((float) y_on_screen) / grid_h) * (max_y - min_y); - } - - public void redraw() { - int repetitions = mandelbrotProvider.getRepetitions(); - - int grid_w = grid.getWidth(), grid_h = grid.getHeight(); - - for (int i = 0; i < grid_w; i++) { - for (int j = 0; j < grid_h; j++) { - double mandel = ((double) Mandelbrot.mandelNumber(getX(i), getY(j), repetitions) * Math.PI) / repetitions; - int[] color = { - (int) (255 * Math.sin(mandel)), - (int) (255 * Math.sin(mandel + Math.PI / 3)), - (int) (255 * Math.sin(mandel + 2 * Math.PI / 3))}; - grid.setPixel(i, j, color); - } - } - } - - public interface MandelbrotProvider { - public double getCenterX(); - public double getCenterY(); - public double getScale(); - public int getRepetitions(); - } - -} |
