-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCell.pde
36 lines (29 loc) · 1.4 KB
/
Cell.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
public abstract class Cell
{
protected color m_Color = color(255, 0, 200); // Default to pink
protected String m_Name = "Default Cell";
/// Stores the lifetime of the cell. Specifically how many generations the cell have survived.
protected int m_LifeTime = 0;
/// Decides the depth of how many neighbours this cell depends on. 1 means it's the very near neighbours
protected int m_NeighbourDepth = 1;
public int getNeightbourDepth() { return m_NeighbourDepth; }
public void increaseLifeTime() { m_LifeTime++; }
public String getCellName() { return m_Name; }
public color getColor() { return m_Color; }
public abstract CellType getCellType();
public abstract Cell updateState(HashMap<CellType, Integer> neighbours);
public void display(int x, int y, int cellPxSize)
{
fill(m_Color);
stroke(0);
rect(x * cellPxSize, y * cellPxSize, cellPxSize, cellPxSize);
}
/// Calculates and returns the amount of neighbours around this cell based on what it's search depth is.
/// If for example percent is 0.5, then half of the count of neighbours are returned etc. percent is normalized.
/// Result is floored (rounded down to nearest integer)
/// Uses formula: neighbours = (2n+1)^2 - 1
protected int getNeighbourByPercent(float percent)
{
return (int) (((2*m_NeighbourDepth+1)*(2*m_NeighbourDepth+1) - 1) * percent);
}
}