aboutsummaryrefslogtreecommitdiff
path: root/Week11 Mandelbrot/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'Week11 Mandelbrot/src/com')
-rw-r--r--Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotView.java (renamed from Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotController.java)15
-rw-r--r--Week11 Mandelbrot/src/com/camilstaps/mandelbrot/ZoomFrame.java28
2 files changed, 22 insertions, 21 deletions
diff --git a/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotController.java b/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotView.java
index f072805..4cb489a 100644
--- a/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotController.java
+++ b/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotView.java
@@ -10,12 +10,12 @@ import fractals.Mandelbrot;
*
* @author camilstaps
*/
-public class MandelbrotController {
+public class MandelbrotView {
private final MandelbrotProvider mandelbrotProvider;
private final Grid grid;
- public MandelbrotController(MandelbrotProvider mp, Grid grid) {
+ public MandelbrotView(MandelbrotProvider mp, Grid grid) {
mandelbrotProvider = mp;
this.grid = grid;
}
@@ -27,7 +27,7 @@ public class MandelbrotController {
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);
+ return min_x + ((double) x_on_screen) * (max_x - min_x) / grid_w;
}
public double getY(int y_on_screen) {
@@ -37,7 +37,7 @@ public class MandelbrotController {
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);
+ return min_y + (((float) y_on_screen) * (max_y - min_y) / grid_h);
}
public void redraw() {
@@ -49,9 +49,10 @@ public class MandelbrotController {
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))};
+ (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))};
+ //int[] color = {(int) (255 * mandel), (int) (255 * mandel), (int) (255 * mandel)};
grid.setPixel(i, j, color);
}
}
diff --git a/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/ZoomFrame.java b/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/ZoomFrame.java
index b7b5a68..1dfa2a7 100644
--- a/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/ZoomFrame.java
+++ b/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/ZoomFrame.java
@@ -17,7 +17,7 @@ import javax.swing.JFrame;
*/
public class ZoomFrame extends JFrame implements MouseListener, MouseMotionListener {
- private MandelbrotController mandelbrotController;
+ private MandelbrotView mandelbrotView;
private MandelbrotTextFields mandelbrotTextFields;
private Graphics graphics;
@@ -31,8 +31,8 @@ public class ZoomFrame extends JFrame implements MouseListener, MouseMotionListe
addMouseMotionListener(this);
}
- public void setMandelbrotController(MandelbrotController mc) {
- mandelbrotController = mc;
+ public void setMandelbrotView(MandelbrotView mv) {
+ mandelbrotView = mv;
}
public void setMandelbrotTextFields(MandelbrotTextFields mtf) {
@@ -52,11 +52,11 @@ public class ZoomFrame extends JFrame implements MouseListener, MouseMotionListe
@Override
public void mouseReleased(MouseEvent me) {
if (me.getX() == start_x && me.getY() == start_y) {
- if (mandelbrotController == null || mandelbrotTextFields == null)
+ if (mandelbrotView == null || mandelbrotTextFields == null)
return;
- mandelbrotTextFields.setCenterX(mandelbrotController.getX(me.getX()));
- mandelbrotTextFields.setCenterY(mandelbrotController.getY(me.getY()));
+ mandelbrotTextFields.setCenterX(mandelbrotView.getX(me.getX()));
+ mandelbrotTextFields.setCenterY(mandelbrotView.getY(me.getY()));
if ((me.getModifiers() & InputEvent.SHIFT_MASK) != 0) {
mandelbrotTextFields.setScale(mandelbrotTextFields.getScale() / 2);
@@ -64,12 +64,12 @@ public class ZoomFrame extends JFrame implements MouseListener, MouseMotionListe
mandelbrotTextFields.setScale(mandelbrotTextFields.getScale() * 2);
}
} else {
- double center_x = (mandelbrotController.getX(me.getX())
- - mandelbrotController.getX(start_x)) / 2
- + mandelbrotController.getX(start_x);
- double center_y = (mandelbrotController.getY(me.getY())
- - mandelbrotController.getY(start_y)) / 2
- + mandelbrotController.getY(start_y);
+ double center_x = (mandelbrotView.getX(me.getX())
+ - mandelbrotView.getX(start_x)) / 2
+ + mandelbrotView.getX(start_x);
+ double center_y = (mandelbrotView.getY(me.getY())
+ - mandelbrotView.getY(start_y)) / 2
+ + mandelbrotView.getY(start_y);
mandelbrotTextFields.setCenterX(center_x);
mandelbrotTextFields.setCenterY(center_y);
@@ -85,7 +85,7 @@ public class ZoomFrame extends JFrame implements MouseListener, MouseMotionListe
mandelbrotTextFields.setScale(scale);
}
- mandelbrotController.redraw();
+ mandelbrotView.redraw();
dragging = false;
}
@@ -137,7 +137,7 @@ public class ZoomFrame extends JFrame implements MouseListener, MouseMotionListe
public void setCenterY(double y);
public double getScale();
public void setScale(double scale);
- public void setRepetitions(double repetitions);
+ public void setRepetitions(int repetitions);
}
}