View Javadoc
1   package org.woehlke.computer.kurzweil.tabs.mandelbrot2julia;
2   
3   import org.woehlke.computer.kurzweil.commons.tabs.TabController;
4   
5   /**
6    * Mandelbrot Set drawn by a Turing Machine.
7    *
8    * (C) 2006 - 2015 Thomas Woehlke.
9    * https://thomas-woehlke.blogspot.com/2016/01/mandelbrot-set-drawn-by-turing-machine.html
10   * @author Thomas Woehlke
11   *
12   * Date: 05.02.2006
13   * Time: 00:36:20
14   */
15  public class MandelbrotController extends Thread implements TabController, Mandelbrot {
16  
17      private volatile MandelbrotModel mandelbrotModel;
18      private volatile MandelbrotTab tab;
19  
20      private final int THREAD_SLEEP_TIME = 1;
21  
22      private volatile Boolean goOn;
23  
24      public MandelbrotController(MandelbrotModel model, MandelbrotTab tab) {
25          this.tab = tab;
26          this.mandelbrotModel = model;
27          goOn = Boolean.TRUE;
28      }
29  
30      public void run() {
31          boolean doIt;
32          do {
33              synchronized (goOn) {
34                  doIt = goOn.booleanValue();
35              }
36              if(this.mandelbrotModel.step()){
37                  this.tab.getCanvas().repaint();
38              }
39              try { sleep(THREAD_SLEEP_TIME); }
40              catch (InterruptedException e) { }
41          }
42          while (doIt);
43      }
44  
45      public void exit() {
46          synchronized (goOn) {
47              goOn = Boolean.FALSE;
48          }
49      }
50  
51  }