preset for 1D CA initial state
This commit is contained in:
@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user