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