preset for 1D CA initial state

This commit is contained in:
Gator
2022-01-11 13:16:42 +01:00
parent 266840aa0b
commit 93f9426f56
4 changed files with 93 additions and 21 deletions

View File

@ -99,17 +99,26 @@ function getDrawingValues(state, acc, cell) {
);
}
// Populates the first state with a single living cell in the center
function create1dStateOneCell(width) {
return [...Array(width)].map(
(cell, index) => {
if (index === width / 2 || index === width + 1 / 2) return 1
return 0
})
}
// Populates the first state of a 1D CA with cells returned
// by initFn
function initialState1d(width, initFn, args) {
function create1dState(width, initFn, args) {
return [...Array(width)].map(
() => initFn(...args),
() => initFn(...args)
);
}
// Populates the first state of a 2D CA with cells returned
// by initFn
function initialState2d(width, height, initFn, args) {
function create2dState(width, height, initFn, args) {
return [...Array(height)].map(
() => [...Array(width)].map(
() => initFn(...args),
@ -118,5 +127,5 @@ function initialState2d(width, height, initFn, args) {
}
export {
getDrawingValues, initialState1d, initialState2d, evolve1d, evolve2d, conwayRules, createBoard,
getDrawingValues, create1dState, create2dState, createBoard, create1dStateOneCell, conwayRules, evolve1d, evolve2d
};