View Javadoc
1   package org.woehlke.computer.kurzweil.dla.model.dendrite;
2   
3   
4   import java.io.Serializable;
5   
6   /**
7    * Diffusion Limited Aggregation.
8    *
9    * (C) 2006 - 2022 Thomas Woehlke.
10   * @author Thomas Woehlke
11   *
12   * @see <a href="https://thomas-woehlke.blogspot.com/2016/01/diffusion-limited-aggregation.html">Blog Arrticle</a>
13   * @see <a href="https://java.woehlke.org/diffusion-limited-aggregation">Maven Project Page</a>
14   * @see <a href="https://github.com/Computer-Kurzweil/diffusion-limited-aggregation">Github</a>
15   *
16   * Date: 27.08.13
17   * Time: 16:56
18   */
19  public class Dendrite implements Serializable {
20  
21      static final long serialVersionUID = 242L;
22  
23      private int worldMap[][];
24      private Point dimensions;
25      private int age=1;
26  
27      public Dendrite(Point dimensions) {
28          this.dimensions = dimensions;
29          worldMap = new int[dimensions.getX()][dimensions.getY()];
30          int x = dimensions.getX() / 2;
31          int y = dimensions.getY() / 2;
32          worldMap[x][y]=age;
33          age++;
34      }
35  
36      public boolean hasDendriteNeighbour(Point pixel){
37          if(worldMap[pixel.getX()][pixel.getY()]==0){
38              Point[] neighbours=pixel.getNeighbourhood(dimensions);
39              for(Point neighbour:neighbours){
40                 if(worldMap[neighbour.getX()][neighbour.getY()]>0){
41                     worldMap[pixel.getX()][pixel.getY()]=age;
42                     age++;
43                     return true;
44                 }
45              }
46              return false;
47          } else {
48             return true;
49          }
50      }
51  
52      public int getAgeForPixel(int x,int y){
53          return worldMap[x][y];
54      }
55  }