Skip to content

Commit

Permalink
feat: Outer-totalistic rules (#3)
Browse files Browse the repository at this point in the history
* feat: read outer-totalistic rule

* feat: add message

* feat: improve style
  • Loading branch information
rei1024 authored Oct 14, 2024
1 parent cdd6c6c commit b28a872
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
8 changes: 8 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ <h2>Input</h2>
>RLE</a
></label
>
(Accept
<a
href="https://conwaylife.com/wiki/Totalistic_Life-like_cellular_automaton"
target="_blank"
rel="noopener"
>outer-totalistic</a
>
rule)
<br />
<textarea
id="inputRLE"
Expand Down
16 changes: 12 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
"preview": "vite preview"
},
"devDependencies": {
"@ca-ts/algo": "npm:@jsr/ca-ts__algo@^0.2.0",
"@ca-ts/algo": "npm:@jsr/ca-ts__algo@^0.4.0",
"@ca-ts/rle": "npm:@jsr/ca-ts__rle@^0.8.0",
"@ca-ts/rule": "npm:@jsr/ca-ts__rule@^0.2.0",
"babylonjs": "^7.29.0",
"typescript": "^5.6.3",
"vite": "^5.4.1"
},
"dependencies": {}
}
}
7 changes: 7 additions & 0 deletions src/lib/setRLE.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import type { BitWorld } from "@ca-ts/algo/bit";
import { parseRLE } from "@ca-ts/rle";
import { parseRule } from "@ca-ts/rule";

export function setRLE(bitWorld: BitWorld, sourceRLE: string) {
const data = parseRLE(sourceRLE);

try {
bitWorld.setRule(parseRule(data.ruleString).transition);
} catch {
bitWorld.setRule({ birth: [3], survive: [2, 3] });
}

const width = data.size?.width ?? 0;
const height = data.size?.height ?? 0;

Expand Down
4 changes: 4 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ canvas {
top: 4px;
}

h2 {
margin-top: 8px;
}

dialog form {
margin: 12px;
}
Expand Down

0 comments on commit b28a872

Please sign in to comment.