/// <summary> /// Generate data for the output texture /// </summary> private void RefreshVisualizer() { var values = new bool[longBitsNum * maxHistLen]; var histLength = history.Count; for (int i = 0; i < histLength; i++) { for (int j = 0; j < longBitsNum - 1; j++) { var idx = j + (((histLength - 1) - i) * longBitsNum); values[idx] = BitUtils.GetULongBit(history[i], j); } } visualizer.RefreshTex(values); }
/// <summary> /// The main part is here /// </summary> private void UpdateCA() { var nextState = 0ul; var currentState = history[history.Count - 1]; for (byte i = 1; i < longBitsNum - 1; i++) { byte neigbhd = 0; ///!@ set 3 bits representing the number of a bit in the rule for (sbyte b = -1; b <= 1; b++) { if (BitUtils.GetULongBit(currentState, i + b)) { neigbhd |= (byte)(1 << b + 1); } } ///!@ set i-th bit of the next state if (BitUtils.GetShortBit(rule, neigbhd)) { nextState |= 1ul << i; } } history.Add(nextState); }