View Javadoc
1   package org.woehlke.computer.kurzweil.tabs.sierpinskitriangle;
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.sierpinskitriangle.model.SierpinskiTriangleTabStateMachine;
8   import org.woehlke.computer.kurzweil.commons.model.turing.MandelbrotTuringMachine;
9   
10  /**
11   * Mandelbrot Set drawn by a Turing Machine.
12   *
13   * (C) 2006 - 2015 Thomas Woehlke.
14   * https://thomas-woehlke.blogspot.com/2016/01/mandelbrot-set-drawn-by-turing-machine.html
15   * @author Thomas Woehlke
16   *
17   * Created by tw on 16.12.2019.
18   */
19  @Getter
20  public class SierpinskiTriangleModel {
21  
22      private volatile GaussianNumberPlane gaussianNumberPlane;
23      private volatile MandelbrotTuringMachine mandelbrotTuringMachine;
24      private volatile SierpinskiTriangleTabStateMachine applicationStateMachine;
25  
26      private volatile ComputerKurzweilProperties properties;
27      private volatile SierpinskiTriangleTab frame;
28  
29      public SierpinskiTriangleModel(ComputerKurzweilProperties properties, SierpinskiTriangleTab 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 SierpinskiTriangleTabStateMachine();
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              case MANDELBROT_ZOOM:
49                  gaussianNumberPlane.zoomIntoTheMandelbrotSet(c);
50                  break;
51              //case JULIA_SET_ZOOM:
52              //    gaussianNumberPlane.zoomIntoTheJuliaSetFor(c);
53              //    break;
54          }
55          return repaint;
56      }
57  
58      public synchronized boolean step() {
59          boolean repaint = false;
60          switch (applicationStateMachine.getApplicationState()) {
61              case MANDELBROT:
62                  repaint = mandelbrotTuringMachine.step();
63                  break;
64              //case JULIA_SET:
65              case MANDELBROT_ZOOM:
66              //case JULIA_SET_ZOOM:
67                  break;
68          }
69          return repaint;
70      }
71  
72      public synchronized int getCellStatusFor(int x, int y) {
73          return gaussianNumberPlane.getCellStatusFor(x, y);
74      }
75  
76      public Point getWorldDimensions() {
77          int width = properties.getAllinone().getLattice().getWidth();
78          int height = properties.getAllinone().getLattice().getHeight();
79          return new Point(width, height);
80      }
81  
82      public void setModeSwitch() {
83          this.applicationStateMachine.setModeSwitch();
84          this.frame.setModeSwitch();
85      }
86  
87      public void setModeZoom() {
88          this.gaussianNumberPlane.setModeZoom();
89          this.applicationStateMachine.setModeZoom();
90          this.frame.setModeZoom();
91      }
92  
93      public GaussianNumberPlane getGaussianNumberPlane() {
94          return gaussianNumberPlane;
95      }
96  
97      public SierpinskiTriangleTab getFrame() {
98          return frame;
99      }
100 
101     public void zoomOut() {
102         switch (applicationStateMachine.getApplicationState()) {
103             case MANDELBROT:
104             //case JULIA_SET:
105                 break;
106             case MANDELBROT_ZOOM:
107                 gaussianNumberPlane.zoomOutOfTheMandelbrotSet();
108                 break;
109             //case JULIA_SET_ZOOM:
110             //    gaussianNumberPlane.zoomOutOfTheJuliaSet();
111             //    break;
112         }
113     }
114 }