aboutsummaryrefslogtreecommitdiff
path: root/Week11 Mandelbrot/src/com/camilstaps/mandelbrot
diff options
context:
space:
mode:
authorCamil Staps2015-04-29 08:46:35 +0200
committerCamil Staps2015-04-29 08:46:35 +0200
commitd18949b065c93f4bc878e57c718be7a5ad1f7ae9 (patch)
tree10837954db64cecf0197a7596fa3338547e172c2 /Week11 Mandelbrot/src/com/camilstaps/mandelbrot
parentWorking mandelbrot function (diff)
Simple interface working
Diffstat (limited to 'Week11 Mandelbrot/src/com/camilstaps/mandelbrot')
-rw-r--r--Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotController.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotController.java b/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotController.java
new file mode 100644
index 0000000..930d589
--- /dev/null
+++ b/Week11 Mandelbrot/src/com/camilstaps/mandelbrot/MandelbrotController.java
@@ -0,0 +1,56 @@
+/*
+ * 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 void redraw() {
+ double centerX = mandelbrotProvider.getCenterX();
+ double centerY = mandelbrotProvider.getCenterY();
+ double scale = mandelbrotProvider.getScale();
+ 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);
+ }
+ }
+ }
+
+ public interface MandelbrotProvider {
+ public double getCenterX();
+ public double getCenterY();
+ public double getScale();
+ public int getRepetitions();
+ }
+
+}