1 package org.woehlke.simulation.dla.model;
2
3 import org.woehlke.simulation.dla.DiffusionLimitedAggregation;
4
5
6
7
8
9
10
11
12
13
14
15 public class Dendrite implements DiffusionLimitedAggregation {
16
17 static final long serialVersionUID = mySerialVersionUID;
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 }