Implement app controller, patterns, controls, and import/export

This commit is contained in:
2026-07-08 19:48:42 +00:00
parent 5f0a510a99
commit f86a7ef5b1
2 changed files with 712 additions and 0 deletions

157
js/patterns.js Normal file
View File

@@ -0,0 +1,157 @@
const block = [
[0, 0],
[0, 1],
[1, 0],
[1, 1],
];
const blinker = [
[0, 0],
[0, 1],
[0, 2],
];
const toad = [
[0, 1],
[0, 2],
[0, 3],
[1, 0],
[1, 1],
[1, 2],
];
const beacon = [
[0, 0],
[0, 1],
[1, 0],
[1, 1],
[2, 2],
[2, 3],
[3, 2],
[3, 3],
];
const glider = [
[0, 1],
[1, 2],
[2, 0],
[2, 1],
[2, 2],
];
const lightweightSpaceship = [
[0, 1],
[0, 2],
[0, 3],
[0, 4],
[1, 0],
[1, 4],
[2, 4],
[3, 0],
[3, 3],
];
const pulsar = [
[0, 2],
[0, 3],
[0, 4],
[0, 8],
[0, 9],
[0, 10],
[2, 0],
[2, 5],
[2, 7],
[2, 12],
[3, 0],
[3, 5],
[3, 7],
[3, 12],
[4, 0],
[4, 5],
[4, 7],
[4, 12],
[5, 2],
[5, 3],
[5, 4],
[5, 8],
[5, 9],
[5, 10],
[7, 2],
[7, 3],
[7, 4],
[7, 8],
[7, 9],
[7, 10],
[8, 0],
[8, 5],
[8, 7],
[8, 12],
[9, 0],
[9, 5],
[9, 7],
[9, 12],
[10, 0],
[10, 5],
[10, 7],
[10, 12],
[12, 2],
[12, 3],
[12, 4],
[12, 8],
[12, 9],
[12, 10],
];
const gosperGliderGun = [
[0, 24],
[1, 22],
[1, 24],
[2, 12],
[2, 13],
[2, 20],
[2, 21],
[2, 34],
[2, 35],
[3, 11],
[3, 15],
[3, 20],
[3, 21],
[3, 34],
[3, 35],
[4, 0],
[4, 1],
[4, 10],
[4, 16],
[4, 20],
[4, 21],
[5, 0],
[5, 1],
[5, 10],
[5, 14],
[5, 16],
[5, 17],
[5, 22],
[5, 24],
[6, 10],
[6, 16],
[6, 24],
[7, 11],
[7, 15],
[8, 12],
[8, 13],
];
export const PATTERNS = [
{ key: "block", label: "Block (still life)", cells: block },
{ key: "blinker", label: "Blinker (oscillator)", cells: blinker },
{ key: "toad", label: "Toad (oscillator)", cells: toad },
{ key: "beacon", label: "Beacon (oscillator)", cells: beacon },
{ key: "glider", label: "Glider", cells: glider },
{ key: "lwss", label: "Lightweight spaceship", cells: lightweightSpaceship },
{ key: "pulsar", label: "Pulsar", cells: pulsar },
{ key: "gosper", label: "Gosper glider gun", cells: gosperGliderGun },
];
export function getPatternByKey(key) {
return PATTERNS.find((pattern) => pattern.key === key) ?? null;
}