View Javadoc
1   package org.woehlke.computer.kurzweil.tabs.kochsnowflake;
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 KochSnowflakeController extends Thread implements Runnable {
14  
15      private final int THREAD_SLEEP_TIME = 1;
16      private volatile KochSnowflakeModel mandelbrotModel;
17      private volatile KochSnowflakeTab frame;
18      private volatile Boolean goOn;
19  
20      public KochSnowflakeController(KochSnowflakeModel model, KochSnowflakeTab frame) {
21          this.frame = frame;
22          this.mandelbrotModel = model;
23          goOn = Boolean.TRUE;
24      }
25  
26      public void run() {
27          boolean doIt;
28          do {
29              synchronized (goOn) {
30                  doIt = goOn.booleanValue();
31              }
32              if(this.mandelbrotModel.step()){
33                  frame.getCanvas().repaint();
34              }
35              try { sleep(THREAD_SLEEP_TIME); }
36              catch (InterruptedException e) { }
37          }
38          while (doIt);
39      }
40  
41      public void exit() {
42          synchronized (goOn) {
43              goOn = Boolean.FALSE;
44          }
45      }
46  
47  }