Godot Nature of Code  1.2.0
Nature of Code implemented in Godot Engine
Public Member Functions | Protected Member Functions | Properties | List of all members
Automata.Cell< T > Class Template Referenceabstract

Generic base cell class. More...

Inherits Node2D.

Public Member Functions

abstract T GetAliveValue ()
 Get alive cell value. More...
 
abstract T GetDeadValue ()
 Get dead cell value. More...
 
virtual bool IsAlive ()
 Check if cell is alive (based on State). More...
 
virtual bool WasAlive ()
 Check if cell was alive (based on PreviousState). More...
 
virtual T RandomizeState ()
 Return a randomized state. More...
 

Protected Member Functions

virtual ? Color GetStateColor ()
 Get state color. Returns null if cell is discarded. More...
 

Properties

PreviousState [get, set]
 Previous state More...
 
State [get, set]
 Current state More...
 
Vector2 Size [get, set]
 Cell size More...
 
Color CellColor = Colors.LightBlue [get, set]
 Cell color More...
 
bool HighlightTransitions [get, set]
 Highlight when a cell is transitioning from life to death More...
 

Detailed Description

Generic base cell class.

Type Constraints
T :System.IEquatable<T> 

Definition at line 36 of file CellularAutomata2D.cs.

Member Function Documentation

◆ GetAliveValue()

abstract T Automata.Cell< T >.GetAliveValue ( )
pure virtual

Get alive cell value.

Returns
Alive cell value

Implemented in Automata.BoolCell.

◆ GetDeadValue()

abstract T Automata.Cell< T >.GetDeadValue ( )
pure virtual

Get dead cell value.

Returns
Dead cell value

Implemented in Automata.BoolCell.

◆ GetStateColor()

virtual ? Color Automata.Cell< T >.GetStateColor ( )
inlineprotectedvirtual

Get state color. Returns null if cell is discarded.

Returns
State color

Definition at line 124 of file CellularAutomata2D.cs.

125  {
126  var wasAlive = WasAlive();
127  var isAlive = IsAlive();
128 
130  {
131  if (!wasAlive && isAlive)
132  {
133  // Cell just lived
134  return Colors.Blue;
135  }
136  else if (wasAlive && !isAlive)
137  {
138  // Cell just died
139  return Colors.Red;
140  }
141  else if (!isAlive)
142  {
143  // Cell already dead
144  return null;
145  }
146  }
147  else if (!isAlive)
148  {
149  // Cell already dead
150  return null;
151  }
152 
153  return CellColor;
154  }
Color CellColor
Cell color
virtual bool WasAlive()
Check if cell was alive (based on PreviousState).
virtual bool IsAlive()
Check if cell is alive (based on State).
bool HighlightTransitions
Highlight when a cell is transitioning from life to death

◆ IsAlive()

virtual bool Automata.Cell< T >.IsAlive ( )
inlinevirtual

Check if cell is alive (based on State).

Returns
Live state

Definition at line 70 of file CellularAutomata2D.cs.

71  {
72  return State.Equals(GetAliveValue());
73  }
T State
Current state
abstract T GetAliveValue()
Get alive cell value.

◆ RandomizeState()

virtual T Automata.Cell< T >.RandomizeState ( )
inlinevirtual

Return a randomized state.

Returns
Randomized state

Definition at line 88 of file CellularAutomata2D.cs.

89  {
90  if (MathUtils.Randf() <= 0.5f)
91  {
92  return GetAliveValue();
93  }
94  else
95  {
96  return GetDeadValue();
97  }
98  }
abstract T GetDeadValue()
Get dead cell value.
Math utility functions
Definition: MathUtils.cs:7
static float Randf()
Return a random floating number between 0 and 1.
Definition: MathUtils.cs:26

◆ WasAlive()

virtual bool Automata.Cell< T >.WasAlive ( )
inlinevirtual

Check if cell was alive (based on PreviousState).

Returns
Previous live state

Definition at line 79 of file CellularAutomata2D.cs.

80  {
81  return PreviousState.Equals(GetAliveValue());
82  }
T PreviousState
Previous state

Property Documentation

◆ CellColor

Color Automata.Cell< T >.CellColor = Colors.LightBlue
getset

Cell color

Definition at line 49 of file CellularAutomata2D.cs.

49 { set; get; } = Colors.LightBlue;

◆ HighlightTransitions

bool Automata.Cell< T >.HighlightTransitions
getset

Highlight when a cell is transitioning from life to death

Definition at line 52 of file CellularAutomata2D.cs.

52 { set; get; }

◆ PreviousState

T Automata.Cell< T >.PreviousState
getset

Previous state

Definition at line 40 of file CellularAutomata2D.cs.

40 { set; get; }

◆ Size

Vector2 Automata.Cell< T >.Size
getset

Cell size

Definition at line 46 of file CellularAutomata2D.cs.

46 { set; get; }

◆ State

T Automata.Cell< T >.State
getset

Current state

Definition at line 43 of file CellularAutomata2D.cs.

43 { set; get; }

The documentation for this class was generated from the following file: