1 package org.woehlke.computer.kurzweil.tabs.mandelbrot2julia;
2
3 import lombok.Getter;
4 import org.woehlke.computer.kurzweil.application.ComputerKurzweilProperties;
5 import org.woehlke.computer.kurzweil.commons.model.fractal.GaussianNumberPlane;
6 import org.woehlke.computer.kurzweil.commons.model.turing.Point;
7 import org.woehlke.computer.kurzweil.tabs.mandelbrot2julia.model.Mandelbrot2JuliaStateMachine;
8 import org.woehlke.computer.kurzweil.commons.model.turing.MandelbrotTuringMachine;
9
10
11
12
13
14
15
16
17
18
19 @Getter
20 public class Mandelbrot2JuliaModel {
21
22 private volatile GaussianNumberPlane gaussianNumberPlane;
23 private volatile MandelbrotTuringMachine mandelbrotTuringMachine;
24 private volatile Mandelbrot2JuliaStateMachine applicationStateMachine;
25
26 private volatile ComputerKurzweilProperties properties;
27 private volatile Mandelbrot2JuliaTab frame;
28
29 public Mandelbrot2JuliaModel(ComputerKurzweilProperties properties, Mandelbrot2JuliaTab frame) {
30 this.properties = properties;
31 this.frame = frame;
32 this.gaussianNumberPlane = new GaussianNumberPlane(this);
33 this.mandelbrotTuringMachine = new MandelbrotTuringMachine(this);
34 this.applicationStateMachine = new Mandelbrot2JuliaStateMachine();
35 }
36
37 public synchronized boolean click(Point c) {
38 applicationStateMachine.click();
39 boolean repaint = true;
40 switch (applicationStateMachine.getApplicationState()) {
41 case MANDELBROT:
42 mandelbrotTuringMachine.start();
43 repaint = false;
44 break;
45 case JULIA_SET:
46 gaussianNumberPlane.computeTheJuliaSetFor(c);
47 break;
48 }
49 return repaint;
50 }
51
52 public synchronized boolean step() {
53 boolean repaint = false;
54 switch (applicationStateMachine.getApplicationState()) {
55 case MANDELBROT:
56 repaint = mandelbrotTuringMachine.step();
57 break;
58 case JULIA_SET:
59 break;
60 }
61 return repaint;
62 }
63
64 public synchronized int getCellStatusFor(int x, int y) {
65 return gaussianNumberPlane.getCellStatusFor(x, y);
66 }
67
68 public Point getWorldDimensions() {
69 int width = properties.getAllinone().getLattice().getWidth();
70 int height = properties.getAllinone().getLattice().getHeight();
71 return new Point(width, height);
72 }
73
74 public void setModeSwitch() {
75
76 this.frame.setModeSwitch();
77 }
78
79 public GaussianNumberPlane getGaussianNumberPlane() {
80 return gaussianNumberPlane;
81 }
82
83 public Mandelbrot2JuliaTab getFrame() {
84 return frame;
85 }
86
87 }