wip optimizing render
This commit is contained in:
@ -91,6 +91,15 @@ function conwayRules(cell, neighbors) {
|
||||
return cell;
|
||||
}
|
||||
|
||||
// Get the next evolution of a cell according to
|
||||
// Conway's game of life rules
|
||||
function servietteRules(cell, neighbors) {
|
||||
// loneliness rule
|
||||
if (cell === 0 && [2, 3, 4].find((x) => x == neighbors)) return 1;
|
||||
// the cell remains the same if none apply
|
||||
return 0;
|
||||
}
|
||||
|
||||
// variation of the game of life where a
|
||||
// cell comes to live if 6 neigbor cells are alive
|
||||
function highLifeRules(cell, neighbors) {
|
||||
@ -200,6 +209,7 @@ export {
|
||||
lonelinessRules,
|
||||
threebornRules,
|
||||
highLifeRules,
|
||||
servietteRules,
|
||||
evolve1d,
|
||||
evolve2d,
|
||||
};
|
||||
|
||||
@ -31,7 +31,7 @@ export function picToBoard(pixels, width, height) {
|
||||
if (index % 4 == 0) {
|
||||
const count = pixels[index] + pixels[index + 1] + pixels[index + 2];
|
||||
const value = count >= 255 ? 1 : 0;
|
||||
acc.push(value);
|
||||
acc[index] = value;
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
@ -77,6 +77,19 @@ const presetRuleset = [
|
||||
"000": 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "unknown rule 2",
|
||||
rules: {
|
||||
100: 1,
|
||||
101: 0,
|
||||
110: 1,
|
||||
111: 0,
|
||||
"011": 0,
|
||||
"010": 0,
|
||||
"001": 0,
|
||||
"000": 1,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const initialStates = [
|
||||
@ -122,6 +135,11 @@ const preset2dRules = [
|
||||
description:
|
||||
"Variation on Conway's Game of Life where a cell live if the six neighbor cells are alive",
|
||||
},
|
||||
{
|
||||
id: "serviette",
|
||||
name: "Serviette variation",
|
||||
description: "bla",
|
||||
},
|
||||
];
|
||||
|
||||
export { presetRuleset, initialStates, preset2dRules };
|
||||
|
||||
Reference in New Issue
Block a user