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