1 package org.woehlke.computer.kurzweil.tabs.mandelbrot2julia;
2
3 import lombok.Getter;
4 import lombok.extern.log4j.Log4j2;
5 import org.woehlke.computer.kurzweil.application.ComputerKurzweilProperties;
6 import org.woehlke.computer.kurzweil.commons.tabs.TabModel;
7 import org.woehlke.computer.kurzweil.commons.model.fractal.GaussianNumberPlane;
8 import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.state.MandelbrotTabStateMachine;
9 import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.turing.MandelbrotTuringMachine;
10 import org.woehlke.computer.kurzweil.tabs.mandelbrotzoom.model.turing.Point;
11
12 import java.util.concurrent.ForkJoinTask;
13
14
15
16
17
18
19
20
21
22
23 @Log4j2
24 @Getter
25 public class MandelbrotModel extends ForkJoinTask<Void> implements TabModel {
26
27 private final GaussianNumberPlane gaussianNumberPlane;
28 private final MandelbrotTuringMachine mandelbrotTuringMachine;
29 private final MandelbrotTabStateMachine mandelbrotTabStateMachine;
30
31 private final ComputerKurzweilProperties properties;
32 private final MandelbrotTab tab;
33
34 public MandelbrotModel(ComputerKurzweilProperties properties, MandelbrotTab tab) {
35 this.properties = properties;
36 this.tab = tab;
37 this.gaussianNumberPlane = new GaussianNumberPlane(this);
38 this.mandelbrotTuringMachine = new MandelbrotTuringMachine(this);
39 this.mandelbrotTabStateMachine = new MandelbrotTabStateMachine();
40 }
41
42 public synchronized boolean click(Point c) {
43 mandelbrotTabStateMachine.click();
44 boolean repaint = true;
45 switch (mandelbrotTabStateMachine.getMandelbrotTabState()) {
46 case MANDELBROT:
47 mandelbrotTuringMachine.start();
48 repaint = false;
49 break;
50 case JULIA_SET:
51 gaussianNumberPlane.computeTheJuliaSetFor(c);
52 break;
53 case MANDELBROT_ZOOM:
54 gaussianNumberPlane.zoomIntoTheMandelbrotSet(c);
55 break;
56 case JULIA_SET_ZOOM:
57 gaussianNumberPlane.zoomIntoTheJuliaSetFor(c);
58 break;
59 }
60 return repaint;
61 }
62
63 public synchronized boolean step() {
64 boolean repaint = false;
65 switch (mandelbrotTabStateMachine.getMandelbrotTabState()) {
66 case MANDELBROT:
67 repaint = mandelbrotTuringMachine.step();
68 break;
69 case JULIA_SET:
70 case MANDELBROT_ZOOM:
71 case JULIA_SET_ZOOM:
72 break;
73 }
74 return repaint;
75 }
76
77 public synchronized int getCellStatusFor(int x, int y) {
78 return gaussianNumberPlane.getCellStatusFor(x, y);
79 }
80
81 public Point getWorldDimensions() {
82 int width = properties.getAllinone().getLattice().getWidth();
83 int height = properties.getAllinone().getLattice().getHeight();
84 return new Point(width, height);
85 }
86
87 public void setModeSwitch() {
88 this.mandelbrotTabStateMachine.setModeSwitch();
89
90 }
91
92 public void setModeZoom() {
93 this.gaussianNumberPlane.setModeZoom();
94 this.mandelbrotTabStateMachine.setModeZoom();
95
96 }
97
98 public GaussianNumberPlane getGaussianNumberPlane() {
99 return gaussianNumberPlane;
100 }
101
102 public MandelbrotTab getTab() {
103 return tab;
104 }
105
106 public void zoomOut() {
107 switch (mandelbrotTabStateMachine.getMandelbrotTabState()) {
108 case MANDELBROT:
109 case JULIA_SET:
110 break;
111 case MANDELBROT_ZOOM:
112 gaussianNumberPlane.zoomOutOfTheMandelbrotSet();
113 break;
114 case JULIA_SET_ZOOM:
115 gaussianNumberPlane.zoomOutOfTheJuliaSet();
116 break;
117 }
118 }
119
120 @Override
121 public Void getRawResult() {
122 return null;
123 }
124
125 @Override
126 protected void setRawResult(Void value) {
127
128 }
129
130 @Override
131 protected boolean exec() {
132 return false;
133 }
134
135 @Override
136 public void start() {
137
138 }
139
140 @Override
141 public void stop() {
142
143 }
144 }