aboutsummaryrefslogtreecommitdiff
path: root/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotView.java
diff options
context:
space:
mode:
authorCamil Staps2015-04-30 17:18:11 +0200
committerCamil Staps2015-04-30 17:18:11 +0200
commit3b4d9eab5128a79bc7f464cbf105798d7af44962 (patch)
tree506ac0167d83da1961c8e5d91adbee6d055eeebf /Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotView.java
parentcleanup (diff)
Cleaned up; javadoc
Diffstat (limited to 'Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotView.java')
-rw-r--r--Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotView.java52
1 files changed, 47 insertions, 5 deletions
diff --git a/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotView.java b/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotView.java
index 4cb489a..fe6a69e 100644
--- a/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotView.java
+++ b/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotView.java
@@ -4,10 +4,9 @@
package com.camilstaps.mandelbrot;
import fractals.Grid;
-import fractals.Mandelbrot;
/**
- *
+ * Showing the Mandelbrot fractal on the screen
* @author camilstaps
*/
public class MandelbrotView {
@@ -15,11 +14,21 @@ public class MandelbrotView {
private final MandelbrotProvider mandelbrotProvider;
private final Grid grid;
+ /**
+ * Get info from a MandelbrotProvider; work with a Grid
+ * @param mp
+ * @param grid
+ */
public MandelbrotView(MandelbrotProvider mp, Grid grid) {
mandelbrotProvider = mp;
this.grid = grid;
}
+ /**
+ * Get the 'mathematical' x value for a certain x coordinate of the screen
+ * @param x_on_screen
+ * @return
+ */
public double getX(int x_on_screen) {
double centerX = mandelbrotProvider.getCenterX();
double scale = mandelbrotProvider.getScale();
@@ -30,6 +39,11 @@ public class MandelbrotView {
return min_x + ((double) x_on_screen) * (max_x - min_x) / grid_w;
}
+ /**
+ * Get the 'mathematical' y value for a certain y coordinate of the screen
+ * @param y_on_screen
+ * @return
+ */
public double getY(int y_on_screen) {
double centerY = mandelbrotProvider.getCenterY();
double scale = mandelbrotProvider.getScale();
@@ -40,6 +54,9 @@ public class MandelbrotView {
return min_y + (((float) y_on_screen) * (max_y - min_y) / grid_h);
}
+ /**
+ * (Re)draw the fractal
+ */
public void redraw() {
int repetitions = mandelbrotProvider.getRepetitions();
@@ -47,21 +64,46 @@ public class MandelbrotView {
for (int i = 0; i < grid_w; i++) {
for (int j = 0; j < grid_h; j++) {
+ // Convert mandel number to some number in [0,pi] to let the colourise below work nicely
double mandel = ((double) Mandelbrot.mandelNumber(getX(i), getY(j), repetitions) * Math.PI) / repetitions;
- int[] color = {
+ // Different mandel numbers have different colours
+ int[] colour = {
(int) (30 + 220 * Math.sin(mandel)),
(int) (30 + 220 * Math.sin(mandel + 2 * Math.PI / 3)),
(int) (30 + 220 * Math.sin(mandel + 4 * Math.PI / 3))};
+ // This is a grayscale version:
//int[] color = {(int) (255 * mandel), (int) (255 * mandel), (int) (255 * mandel)};
- grid.setPixel(i, j, color);
+ grid.setPixel(i, j, colour);
}
}
}
-
+
+ /**
+ * Get user input
+ */
public interface MandelbrotProvider {
+ /**
+ * Get center X value
+ * @return
+ */
public double getCenterX();
+
+ /**
+ * Get center Y value
+ * @return
+ */
public double getCenterY();
+
+ /**
+ * Get scale factor
+ * @return
+ */
public double getScale();
+
+ /**
+ * Get max amount of iterations for the mandel function
+ * @return
+ */
public int getRepetitions();
}