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