aboutsummaryrefslogtreecommitdiff
path: root/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotController.java
diff options
context:
space:
mode:
Diffstat (limited to 'Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotController.java')
-rw-r--r--Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotController.java41
1 files changed, 26 insertions, 15 deletions
diff --git a/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotController.java b/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotController.java
index 930d589..f072805 100644
--- a/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotController.java
+++ b/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotController.java
@@ -20,28 +20,39 @@ public class MandelbrotController {
this.grid = grid;
}
- public void redraw() {
+ 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();
- double min_x = centerX - grid_w / scale / 2,
- max_x = centerX + grid_w / scale / 2,
- min_y = centerY - grid_h / scale / 2,
- max_y = centerX + grid_h / scale / 2;
-
- for (float i = 0; i < grid_w; i++) {
- for (float j = 0; j < grid_h; j++) {
- int grayscale = Mandelbrot.mandelNumber(
- min_x + (i / grid_w) * (max_x - min_x),
- min_y + (j / grid_h) * (max_y - min_y),
- repetitions
- ) * 255 / repetitions;
- int[] color = {grayscale, grayscale, grayscale};
- grid.setPixel((int) i, (int) j, color);
+ 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);
}
}
}