Merge pull request 'pinia-migration' (#2) from pinia-migration into master
Reviewed-on: #2
This commit is contained in:
commit
1264c2fbbe
9
.pre-commit-config.yaml
Normal file
9
.pre-commit-config.yaml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/mirrors-eslint
|
||||||
|
rev: "v8.28.0"
|
||||||
|
hooks:
|
||||||
|
- id: eslint
|
||||||
|
- repo: https://github.com/pre-commit/mirrors-prettier
|
||||||
|
rev: "v2.7.1"
|
||||||
|
hooks:
|
||||||
|
- id: prettier
|
@ -1 +1,3 @@
|
|||||||
{}
|
{
|
||||||
|
"vueIndentScriptAndStyle": true
|
||||||
|
}
|
||||||
|
12
README.md
12
README.md
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
Explore 1D and 2D cellular automata, with a few bells and whistles.
|
Explore 1D and 2D cellular automata, with a few bells and whistles.
|
||||||
|
|
||||||
|
![rules73](./example.png)
|
||||||
|
|
||||||
## Project setup
|
## Project setup
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -11,7 +13,7 @@ npm install
|
|||||||
### Compiles and hot-reloads for development
|
### Compiles and hot-reloads for development
|
||||||
|
|
||||||
```
|
```
|
||||||
npm run serve
|
npm run dev
|
||||||
```
|
```
|
||||||
|
|
||||||
### Compiles and minifies for production
|
### Compiles and minifies for production
|
||||||
@ -26,9 +28,15 @@ npm run build
|
|||||||
npm run lint
|
npm run lint
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Format files
|
||||||
|
|
||||||
|
```
|
||||||
|
npm run format
|
||||||
|
```
|
||||||
|
|
||||||
### Customize configuration
|
### Customize configuration
|
||||||
|
|
||||||
See [Configuration Reference](https://cli.vuejs.org/config/).
|
See [Configuration Reference](https://vitejs.dev/guide/).
|
||||||
|
|
||||||
### References
|
### References
|
||||||
|
|
||||||
|
BIN
example.png
Normal file
BIN
example.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 103 KiB |
90
package-lock.json
generated
90
package-lock.json
generated
@ -10,9 +10,9 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@vitejs/plugin-vue": "^3.2.0",
|
"@vitejs/plugin-vue": "^3.2.0",
|
||||||
"install": "^0.13.0",
|
"install": "^0.13.0",
|
||||||
|
"pinia": "^2.0.27",
|
||||||
"vite": "^3.2.4",
|
"vite": "^3.2.4",
|
||||||
"vue": "3.2",
|
"vue": "3.2"
|
||||||
"vuex": "4.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^8.28.0",
|
"eslint": "^8.28.0",
|
||||||
@ -1548,6 +1548,56 @@
|
|||||||
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",
|
||||||
"integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ=="
|
"integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ=="
|
||||||
},
|
},
|
||||||
|
"node_modules/pinia": {
|
||||||
|
"version": "2.0.27",
|
||||||
|
"resolved": "https://registry.npmjs.org/pinia/-/pinia-2.0.27.tgz",
|
||||||
|
"integrity": "sha512-nOnXP0OFeL8R4WjAHsterU+11vptda643gH02xKNtSCDPiRzVfRYodOLihLDoa0gL1KKuQKV+KOzEgdt3YvqEw==",
|
||||||
|
"dependencies": {
|
||||||
|
"@vue/devtools-api": "^6.4.5",
|
||||||
|
"vue-demi": "*"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/posva"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@vue/composition-api": "^1.4.0",
|
||||||
|
"typescript": ">=4.4.4",
|
||||||
|
"vue": "^2.6.14 || ^3.2.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@vue/composition-api": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"typescript": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/pinia/node_modules/vue-demi": {
|
||||||
|
"version": "0.13.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/vue-demi/-/vue-demi-0.13.11.tgz",
|
||||||
|
"integrity": "sha512-IR8HoEEGM65YY3ZJYAjMlKygDQn25D5ajNFNoKh9RSDMQtlzCxtfQjdQgv9jjK+m3377SsJXY8ysq8kLCZL25A==",
|
||||||
|
"hasInstallScript": true,
|
||||||
|
"bin": {
|
||||||
|
"vue-demi-fix": "bin/vue-demi-fix.js",
|
||||||
|
"vue-demi-switch": "bin/vue-demi-switch.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/antfu"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@vue/composition-api": "^1.0.0-rc.1",
|
||||||
|
"vue": "^3.0.0-0 || ^2.6.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@vue/composition-api": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/postcss": {
|
"node_modules/postcss": {
|
||||||
"version": "8.4.19",
|
"version": "8.4.19",
|
||||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.19.tgz",
|
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.19.tgz",
|
||||||
@ -1969,17 +2019,6 @@
|
|||||||
"eslint": ">=6.0.0"
|
"eslint": ">=6.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/vuex": {
|
|
||||||
"version": "4.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/vuex/-/vuex-4.1.0.tgz",
|
|
||||||
"integrity": "sha512-hmV6UerDrPcgbSy9ORAtNXDr9M4wlNP4pEFKye4ujJF8oqgFFuxDCdOLS3eNoRTtq5O3hoBDh9Doj1bQMYHRbQ==",
|
|
||||||
"dependencies": {
|
|
||||||
"@vue/devtools-api": "^6.0.0-beta.11"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"vue": "^3.2.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/which": {
|
"node_modules/which": {
|
||||||
"version": "2.0.2",
|
"version": "2.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
||||||
@ -3083,6 +3122,23 @@
|
|||||||
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",
|
||||||
"integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ=="
|
"integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ=="
|
||||||
},
|
},
|
||||||
|
"pinia": {
|
||||||
|
"version": "2.0.27",
|
||||||
|
"resolved": "https://registry.npmjs.org/pinia/-/pinia-2.0.27.tgz",
|
||||||
|
"integrity": "sha512-nOnXP0OFeL8R4WjAHsterU+11vptda643gH02xKNtSCDPiRzVfRYodOLihLDoa0gL1KKuQKV+KOzEgdt3YvqEw==",
|
||||||
|
"requires": {
|
||||||
|
"@vue/devtools-api": "^6.4.5",
|
||||||
|
"vue-demi": "*"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"vue-demi": {
|
||||||
|
"version": "0.13.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/vue-demi/-/vue-demi-0.13.11.tgz",
|
||||||
|
"integrity": "sha512-IR8HoEEGM65YY3ZJYAjMlKygDQn25D5ajNFNoKh9RSDMQtlzCxtfQjdQgv9jjK+m3377SsJXY8ysq8kLCZL25A==",
|
||||||
|
"requires": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"postcss": {
|
"postcss": {
|
||||||
"version": "8.4.19",
|
"version": "8.4.19",
|
||||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.19.tgz",
|
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.19.tgz",
|
||||||
@ -3324,14 +3380,6 @@
|
|||||||
"semver": "^7.3.6"
|
"semver": "^7.3.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"vuex": {
|
|
||||||
"version": "4.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/vuex/-/vuex-4.1.0.tgz",
|
|
||||||
"integrity": "sha512-hmV6UerDrPcgbSy9ORAtNXDr9M4wlNP4pEFKye4ujJF8oqgFFuxDCdOLS3eNoRTtq5O3hoBDh9Doj1bQMYHRbQ==",
|
|
||||||
"requires": {
|
|
||||||
"@vue/devtools-api": "^6.0.0-beta.11"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"which": {
|
"which": {
|
||||||
"version": "2.0.2",
|
"version": "2.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
||||||
|
@ -12,9 +12,9 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@vitejs/plugin-vue": "^3.2.0",
|
"@vitejs/plugin-vue": "^3.2.0",
|
||||||
"install": "^0.13.0",
|
"install": "^0.13.0",
|
||||||
|
"pinia": "^2.0.27",
|
||||||
"vite": "^3.2.4",
|
"vite": "^3.2.4",
|
||||||
"vue": "3.2",
|
"vue": "3.2"
|
||||||
"vuex": "4.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^8.28.0",
|
"eslint": "^8.28.0",
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
import { mapActions, mapState, mapWritableState } from "pinia";
|
||||||
|
import { globalStore } from "../stores/index.js";
|
||||||
import {
|
import {
|
||||||
create1dState,
|
create1dState,
|
||||||
create1dStateOneCell,
|
create1dStateOneCell,
|
||||||
@ -18,7 +20,7 @@ import {
|
|||||||
evolve2d,
|
evolve2d,
|
||||||
} from "../modules/automata.js";
|
} from "../modules/automata.js";
|
||||||
import { getRandomInt, sleep } from "../modules/common.js";
|
import { getRandomInt, sleep } from "../modules/common.js";
|
||||||
import { mapGetters } from "vuex";
|
|
||||||
export default {
|
export default {
|
||||||
name: "CanvasBoard",
|
name: "CanvasBoard",
|
||||||
data() {
|
data() {
|
||||||
@ -28,20 +30,22 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters({
|
...mapState(globalStore, {
|
||||||
cellProperties: "getCellProperties",
|
cellProperties: "cellProperties",
|
||||||
rules: "get1dRules",
|
rules: "rules1d",
|
||||||
canvasWidth: "getCanvasWidth",
|
refreshRate: "refreshRate",
|
||||||
canvasHeight: "getCanvasHeight",
|
initial1dState: "initial1dState",
|
||||||
refreshRate: "getRefreshRate",
|
drawingDirection: "drawingDirection",
|
||||||
initial1dState: "getInitial1dState",
|
canDraw: "canDraw",
|
||||||
drawingDirection: "getDrawingDirection",
|
getDraw1d: "draw1d",
|
||||||
canDraw: "getCanDraw",
|
getDraw2d: "draw2d",
|
||||||
lastBoard: "getLastBoard",
|
getDraw2dLast: "draw2dLast",
|
||||||
getDraw1d: "getDraw1d",
|
}),
|
||||||
getDraw2d: "getDraw2d",
|
...mapWritableState(globalStore, {
|
||||||
getDraw2dLast: "getDraw2dLast",
|
lastBoard: "lastBoard",
|
||||||
getReset: "getReset",
|
canvasWidth: "canvasWidth",
|
||||||
|
canvasHeight: "canvasHeight",
|
||||||
|
getReset: "reset",
|
||||||
}),
|
}),
|
||||||
boardWidth: function () {
|
boardWidth: function () {
|
||||||
return Math.floor(this.canvasWidth / this.cellProperties.size);
|
return Math.floor(this.canvasWidth / this.cellProperties.size);
|
||||||
@ -67,13 +71,11 @@ export default {
|
|||||||
mounted() {
|
mounted() {
|
||||||
this.canvas = Object.freeze(document.getElementById("canvas-board"));
|
this.canvas = Object.freeze(document.getElementById("canvas-board"));
|
||||||
this.ctx = this.canvas.getContext("2d");
|
this.ctx = this.canvas.getContext("2d");
|
||||||
this.$store.commit("setCanvasWidth", this.canvas.parentElement.clientWidth);
|
this.canvasWidth = this.canvas.parentElement.clientWidth;
|
||||||
this.$store.commit(
|
this.canvasHeight = this.canvas.parentElement.clientHeight;
|
||||||
"setCanvasHeight",
|
|
||||||
this.canvas.parentElement.clientHeight
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
...mapActions(globalStore, ["toggleStop"]),
|
||||||
drawCanvas(board) {
|
drawCanvas(board) {
|
||||||
const props = this.cellProperties;
|
const props = this.cellProperties;
|
||||||
board.map((row, y) => {
|
board.map((row, y) => {
|
||||||
@ -102,9 +104,9 @@ export default {
|
|||||||
this.rules.rules,
|
this.rules.rules,
|
||||||
this.boardWidth
|
this.boardWidth
|
||||||
);
|
);
|
||||||
this.$store.commit("setLastBoard", Object.freeze(board));
|
this.lastBoard = Object.freeze(board);
|
||||||
this.drawCanvas(board);
|
this.drawCanvas(board);
|
||||||
this.$store.dispatch("stop");
|
this.toggleStop();
|
||||||
},
|
},
|
||||||
draw2d(board) {
|
draw2d(board) {
|
||||||
if (!this.canDraw) return;
|
if (!this.canDraw) return;
|
||||||
@ -125,16 +127,16 @@ export default {
|
|||||||
[0, 2]
|
[0, 2]
|
||||||
);
|
);
|
||||||
const board = evolve2d(initialState, conwayRules);
|
const board = evolve2d(initialState, conwayRules);
|
||||||
this.$store.commit("setLastBoard", Object.freeze(board));
|
this.lastBoard = Object.freeze(board);
|
||||||
this.draw2d(board);
|
this.draw2d(board);
|
||||||
},
|
},
|
||||||
async draw2dLast() {
|
async draw2dLast() {
|
||||||
this.draw2d(this.lastBoard);
|
if (this.lastBoard != undefined) this.draw2d(this.lastBoard);
|
||||||
},
|
},
|
||||||
reset() {
|
reset() {
|
||||||
this.$store.dispatch("stop");
|
this.toggleStop();
|
||||||
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
||||||
this.$store.commit("toggleReset", 0);
|
this.getReset = 0;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -2,55 +2,50 @@
|
|||||||
<MenuRow row-title="2D Cellular Automata">
|
<MenuRow row-title="2D Cellular Automata">
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
<label>Start from last result</label>
|
<label>Start from last result</label>
|
||||||
<input type="button" value="start" @click="draw2dLast" />
|
<input type="button" value="start" @click="toggleDraw2dLast()" />
|
||||||
</div>
|
</div>
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
<input type="button" name="start2d" value="start" @click="draw2d" />
|
<input
|
||||||
|
type="button"
|
||||||
|
name="start2d"
|
||||||
|
value="start"
|
||||||
|
@click="toggleDraw2d()"
|
||||||
|
/>
|
||||||
<input
|
<input
|
||||||
type="button"
|
type="button"
|
||||||
name="stop"
|
name="stop"
|
||||||
class="stop"
|
class="stop"
|
||||||
value="stop"
|
value="stop"
|
||||||
@click="stop"
|
@click="toggleStop()"
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
type="button"
|
type="button"
|
||||||
name="reset"
|
name="reset"
|
||||||
class="reset"
|
class="reset"
|
||||||
value="reset"
|
value="reset"
|
||||||
@click="reset"
|
@click="toggleReset()"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</MenuRow>
|
</MenuRow>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { mapActions } from "pinia";
|
||||||
import MenuRow from "./MenuRow.vue";
|
import MenuRow from "./MenuRow.vue";
|
||||||
import { mapGetters } from "vuex";
|
import { globalStore } from "../stores/index.js";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Menu2dCA",
|
name: "Menu2dCA",
|
||||||
components: {
|
components: {
|
||||||
MenuRow,
|
MenuRow,
|
||||||
},
|
},
|
||||||
computed: {
|
|
||||||
...mapGetters({
|
|
||||||
lastBoard: "getLastBoard",
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
draw2d() {
|
...mapActions(globalStore, [
|
||||||
this.$store.dispatch("draw2d");
|
"toggleDraw2d",
|
||||||
},
|
"toggleDraw2dLast",
|
||||||
draw2dLast() {
|
"toggleReset",
|
||||||
this.$store.dispatch("draw2dLast");
|
"toggleStop",
|
||||||
},
|
]),
|
||||||
reset() {
|
|
||||||
this.$store.dispatch("reset");
|
|
||||||
},
|
|
||||||
stop() {
|
|
||||||
this.$store.dispatch("stop");
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -34,28 +34,26 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { mapWritableState } from "pinia";
|
||||||
|
import { globalStore } from "../stores/index.js";
|
||||||
import MenuRow from "./MenuRow.vue";
|
import MenuRow from "./MenuRow.vue";
|
||||||
export default {
|
export default {
|
||||||
name: "MainMenu",
|
name: "MainMenu",
|
||||||
components: {
|
components: {
|
||||||
MenuRow,
|
MenuRow,
|
||||||
},
|
},
|
||||||
data() {
|
computed: {
|
||||||
return {
|
...mapWritableState(globalStore, ["cellProperties"]),
|
||||||
cellProperties: this.$store.state.cellProperties,
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getCellProperties(event) {
|
getCellProperties(event) {
|
||||||
const elem = event.target;
|
const elem = event.target;
|
||||||
const prop = this.$store.state.cellProperties;
|
const prop = this.cellProperties;
|
||||||
return prop[elem.name];
|
return prop[elem.name];
|
||||||
},
|
},
|
||||||
updateCellProperties(event) {
|
updateCellProperties(event) {
|
||||||
const elem = event.target;
|
const elem = event.target;
|
||||||
const prop = { name: elem.name, value: elem.value };
|
this.cellProperties[elem.name] = elem.value;
|
||||||
//console.log(prop)
|
|
||||||
this.$store.commit("setCellProperties", prop);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -63,20 +63,22 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
<input type="button" name="start" value="start" @click="draw1d" />
|
<input type="button" name="start" value="start" @click="toggleDraw1d()" />
|
||||||
<input
|
<input
|
||||||
type="button"
|
type="button"
|
||||||
name="reset"
|
name="reset"
|
||||||
class="reset"
|
class="reset"
|
||||||
value="reset"
|
value="reset"
|
||||||
@click="reset"
|
@click="toggleReset"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</MenuRow>
|
</MenuRow>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapGetters } from "vuex";
|
import { mapActions, mapWritableState } from "pinia";
|
||||||
|
import { presetRules, initialStates } from "./preset.js";
|
||||||
|
import { globalStore } from "../stores/index.js";
|
||||||
import MenuRow from "./MenuRow.vue";
|
import MenuRow from "./MenuRow.vue";
|
||||||
export default {
|
export default {
|
||||||
name: "MenuElementaryCA",
|
name: "MenuElementaryCA",
|
||||||
@ -84,108 +86,18 @@ export default {
|
|||||||
MenuRow,
|
MenuRow,
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
// TODO: Why not a getter in the store?
|
|
||||||
return {
|
return {
|
||||||
presetRules: [
|
presetRules: presetRules,
|
||||||
{
|
initialStates: initialStates,
|
||||||
name: "rule 73",
|
|
||||||
rules: {
|
|
||||||
100: 0,
|
|
||||||
101: 0,
|
|
||||||
110: 1,
|
|
||||||
111: 0,
|
|
||||||
"011": 1,
|
|
||||||
"010": 0,
|
|
||||||
"001": 0,
|
|
||||||
"000": 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "rule 86",
|
|
||||||
rules: {
|
|
||||||
100: 1,
|
|
||||||
101: 0,
|
|
||||||
110: 0,
|
|
||||||
111: 1,
|
|
||||||
"011": 0,
|
|
||||||
"010": 1,
|
|
||||||
"001": 0,
|
|
||||||
"000": 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "rule 90",
|
|
||||||
rules: {
|
|
||||||
100: 1,
|
|
||||||
101: 0,
|
|
||||||
110: 1,
|
|
||||||
111: 0,
|
|
||||||
"011": 0,
|
|
||||||
"010": 0,
|
|
||||||
"001": 1,
|
|
||||||
"000": 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "rule 45?",
|
|
||||||
rules: {
|
|
||||||
100: 0,
|
|
||||||
101: 0,
|
|
||||||
110: 1,
|
|
||||||
111: 0,
|
|
||||||
"011": 1,
|
|
||||||
"010": 0,
|
|
||||||
"001": 1,
|
|
||||||
"000": 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "rule 54?",
|
|
||||||
rules: {
|
|
||||||
100: 1,
|
|
||||||
101: 0,
|
|
||||||
110: 1,
|
|
||||||
111: 1,
|
|
||||||
"011": 0,
|
|
||||||
"010": 1,
|
|
||||||
"001": 1,
|
|
||||||
"000": 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "unknown rule",
|
|
||||||
rules: {
|
|
||||||
100: 0,
|
|
||||||
101: 0,
|
|
||||||
110: 0,
|
|
||||||
111: 1,
|
|
||||||
"011": 0,
|
|
||||||
"010": 0,
|
|
||||||
"001": 1,
|
|
||||||
"000": 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
initialStates: [
|
|
||||||
{
|
|
||||||
id: "onecell",
|
|
||||||
name: "One cell at center",
|
|
||||||
description: "State with a single cell in the middle",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "random",
|
|
||||||
name: "Random cell",
|
|
||||||
description: "State populated with random cells",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters({
|
...mapWritableState(globalStore, {
|
||||||
initialState: "getInitial1dState",
|
initialState: "initial1dState",
|
||||||
rules: "get1dRules",
|
rules: "rules1d",
|
||||||
}),
|
}),
|
||||||
rules1dFileName() {
|
rules1dFileName() {
|
||||||
|
// TODO: broken
|
||||||
return (
|
return (
|
||||||
Object.keys(this.rules)
|
Object.keys(this.rules)
|
||||||
.map((index) => {
|
.map((index) => {
|
||||||
@ -196,6 +108,7 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
...mapActions(globalStore, ["toggleDraw1d", "toggleReset"]),
|
||||||
copyRules() {
|
copyRules() {
|
||||||
const rules = JSON.stringify(this.rules);
|
const rules = JSON.stringify(this.rules);
|
||||||
navigator.clipboard.writeText(rules);
|
navigator.clipboard.writeText(rules);
|
||||||
@ -207,30 +120,19 @@ export default {
|
|||||||
updateSingleRule(event) {
|
updateSingleRule(event) {
|
||||||
const elem = event.target;
|
const elem = event.target;
|
||||||
const value = elem.checked ? 1 : 0;
|
const value = elem.checked ? 1 : 0;
|
||||||
const data = { rule: elem.name, value: value };
|
this.rules.rules[elem.name] = value;
|
||||||
this.$store.commit("update1dSingleRule", data);
|
|
||||||
},
|
},
|
||||||
updateRules(event) {
|
updateRules(event) {
|
||||||
// TODO : change this, awfully confusing
|
|
||||||
const elem = event.target;
|
const elem = event.target;
|
||||||
const name = elem.value;
|
const name = elem.value;
|
||||||
const rules = this.presetRules.find((ruleset) => {
|
const newRuleset = this.presetRules.find((ruleset) => {
|
||||||
return ruleset.name === name;
|
return ruleset.name === name;
|
||||||
});
|
});
|
||||||
Object.keys(rules.rules).map((value) => {
|
this.rules.rules = newRuleset.rules;
|
||||||
const data = { name: name, rule: value, value: rules.rules[value] };
|
|
||||||
this.$store.commit("update1dSingleRule", data);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
updateInitialState(event) {
|
updateInitialState(event) {
|
||||||
const elem = event.target;
|
const elem = event.target;
|
||||||
this.$store.commit("setInitial1dState", elem.value);
|
this.initialState = elem.value;
|
||||||
},
|
|
||||||
draw1d() {
|
|
||||||
this.$store.dispatch("draw1d");
|
|
||||||
},
|
|
||||||
reset() {
|
|
||||||
this.$store.dispatch("reset");
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -56,39 +56,39 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { mapWritableState } from "pinia";
|
||||||
|
import { globalStore } from "../stores/index.js";
|
||||||
import MenuRow from "./MenuRow.vue";
|
import MenuRow from "./MenuRow.vue";
|
||||||
import { mapGetters } from "vuex";
|
|
||||||
export default {
|
export default {
|
||||||
name: "MenuGeneralOptions",
|
name: "MenuGeneralOptions",
|
||||||
components: {
|
components: {
|
||||||
MenuRow,
|
MenuRow,
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters({
|
...mapWritableState(globalStore, [
|
||||||
canvasWidth: "getCanvasWidth",
|
"canvasWidth",
|
||||||
canvasHeight: "getCanvasHeight",
|
"canvasHeight",
|
||||||
refreshRate: "getRefreshRate",
|
"refreshRate",
|
||||||
drawingDirection: "getDrawingDirection",
|
"drawingDirection",
|
||||||
}),
|
]),
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
updateCanvasHeight: function (event) {
|
updateCanvasHeight: function (event) {
|
||||||
const elem = event.target;
|
const elem = event.target;
|
||||||
this.$store.commit("setCanvasHeight", elem.value);
|
this.canvasHeight = elem.value;
|
||||||
},
|
},
|
||||||
updateCanvasWidth: function (event) {
|
updateCanvasWidth: function (event) {
|
||||||
const elem = event.target;
|
const elem = event.target;
|
||||||
this.$store.commit("setCanvasWidth", elem.value);
|
this.canvasWidth = elem.value;
|
||||||
},
|
},
|
||||||
updateRefreshRate: function (event) {
|
updateRefreshRate: function (event) {
|
||||||
const elem = event.target;
|
const elem = event.target;
|
||||||
this.$store.commit("setRefreshRate", elem.value);
|
this.refreshRate = elem.value;
|
||||||
},
|
},
|
||||||
updateDrawingDirection: function (event) {
|
updateDrawingDirection: function (event) {
|
||||||
const elem = event.target;
|
const elem = event.target;
|
||||||
const value = elem.checked ? "x" : "y";
|
const value = elem.checked ? "x" : "y";
|
||||||
this.$store.commit("setDrawingDirection", value);
|
this.drawingDirection = value;
|
||||||
console.log(this.drawingDirection);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapGetters } from "vuex";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "MenuRow",
|
name: "MenuRow",
|
||||||
props: {
|
props: {
|
||||||
@ -20,17 +18,17 @@ export default {
|
|||||||
default: "",
|
default: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
data() {
|
||||||
...mapGetters({
|
return {
|
||||||
activeMenu: "getActiveMenu",
|
activeMenu: "",
|
||||||
}),
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
updateActiveMenu(event) {
|
updateActiveMenu(event) {
|
||||||
const elem = event.target;
|
const elem = event.target;
|
||||||
const value = elem.id;
|
const value = elem.id;
|
||||||
if (value == this.activeMenu) this.$store.commit("setActiveMenu", "");
|
if (value == this.activeMenu) this.activeMenu = "";
|
||||||
else this.$store.commit("setActiveMenu", value);
|
else this.activeMenu = value;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
95
src/components/preset.js
Normal file
95
src/components/preset.js
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
const presetRules = [
|
||||||
|
{
|
||||||
|
name: "rule 73",
|
||||||
|
rules: {
|
||||||
|
100: 0,
|
||||||
|
101: 0,
|
||||||
|
110: 1,
|
||||||
|
111: 0,
|
||||||
|
"011": 1,
|
||||||
|
"010": 0,
|
||||||
|
"001": 0,
|
||||||
|
"000": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rule 86",
|
||||||
|
rules: {
|
||||||
|
100: 1,
|
||||||
|
101: 0,
|
||||||
|
110: 0,
|
||||||
|
111: 1,
|
||||||
|
"011": 0,
|
||||||
|
"010": 1,
|
||||||
|
"001": 0,
|
||||||
|
"000": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rule 90",
|
||||||
|
rules: {
|
||||||
|
100: 1,
|
||||||
|
101: 0,
|
||||||
|
110: 1,
|
||||||
|
111: 0,
|
||||||
|
"011": 0,
|
||||||
|
"010": 0,
|
||||||
|
"001": 1,
|
||||||
|
"000": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rule 45?",
|
||||||
|
rules: {
|
||||||
|
100: 0,
|
||||||
|
101: 0,
|
||||||
|
110: 1,
|
||||||
|
111: 0,
|
||||||
|
"011": 1,
|
||||||
|
"010": 0,
|
||||||
|
"001": 1,
|
||||||
|
"000": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "rule 54?",
|
||||||
|
rules: {
|
||||||
|
100: 1,
|
||||||
|
101: 0,
|
||||||
|
110: 1,
|
||||||
|
111: 1,
|
||||||
|
"011": 0,
|
||||||
|
"010": 1,
|
||||||
|
"001": 1,
|
||||||
|
"000": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "unknown rule",
|
||||||
|
rules: {
|
||||||
|
100: 0,
|
||||||
|
101: 0,
|
||||||
|
110: 0,
|
||||||
|
111: 1,
|
||||||
|
"011": 0,
|
||||||
|
"010": 0,
|
||||||
|
"001": 1,
|
||||||
|
"000": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const initialStates = [
|
||||||
|
{
|
||||||
|
id: "onecell",
|
||||||
|
name: "One cell at center",
|
||||||
|
description: "State with a single cell in the middle",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "random",
|
||||||
|
name: "Random cell",
|
||||||
|
description: "State populated with random cells",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export { presetRules, initialStates };
|
@ -1,9 +1,10 @@
|
|||||||
import { createApp } from "vue";
|
import { createApp } from "vue";
|
||||||
import App from "./App.vue";
|
import App from "./App.vue";
|
||||||
import { store } from "./store";
|
import { createPinia } from "pinia";
|
||||||
|
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
|
const pinia = createPinia();
|
||||||
|
|
||||||
app.use(store);
|
app.use(pinia);
|
||||||
|
|
||||||
app.mount("#app");
|
app.mount("#app");
|
||||||
|
@ -1,174 +0,0 @@
|
|||||||
/* TODO: terminology is to be changed for :
|
|
||||||
canvas/board :
|
|
||||||
currently, the canvas object is named board,
|
|
||||||
while the structure used to store automata current state is named "board" as well. This is confusing
|
|
||||||
drawing board could be enough to lift any ambiguity
|
|
||||||
|
|
||||||
rules:
|
|
||||||
confusion bewteen ruleset and rules.
|
|
||||||
it's never clear if we refers to a rule or the whole (named) set
|
|
||||||
*/
|
|
||||||
import { createStore } from "vuex";
|
|
||||||
|
|
||||||
export const store = createStore({
|
|
||||||
strict: process.env.NODE_ENV !== "production",
|
|
||||||
state: {
|
|
||||||
rules1d: {
|
|
||||||
name: "rule 73",
|
|
||||||
rules: {
|
|
||||||
111: 0,
|
|
||||||
110: 1,
|
|
||||||
101: 0,
|
|
||||||
100: 0,
|
|
||||||
"011": 1,
|
|
||||||
"010": 0,
|
|
||||||
"001": 0,
|
|
||||||
"000": 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
cellProperties: {
|
|
||||||
size: 3,
|
|
||||||
liveColor: "#000000",
|
|
||||||
deadColor: "#F5F5F5",
|
|
||||||
},
|
|
||||||
canvasWidth: 0,
|
|
||||||
canvasHeight: 0,
|
|
||||||
boardWidth: 0,
|
|
||||||
boardHeight: 0,
|
|
||||||
refreshRate: 300,
|
|
||||||
initial1dState: "onecell",
|
|
||||||
activeMenu: "",
|
|
||||||
drawingDirection: "y",
|
|
||||||
lastBoard: {},
|
|
||||||
draw1d: false,
|
|
||||||
draw2d: false,
|
|
||||||
draw2dLast: false,
|
|
||||||
reset: false,
|
|
||||||
canDraw: true,
|
|
||||||
},
|
|
||||||
mutations: {
|
|
||||||
update1dSingleRule(state, data) {
|
|
||||||
state.rules1d.name = data.name;
|
|
||||||
state.rules1d.rules[data.rule] = data.value;
|
|
||||||
},
|
|
||||||
update1dRules(state, data) {
|
|
||||||
state.rules1d = data;
|
|
||||||
},
|
|
||||||
setCellProperties(state, data) {
|
|
||||||
state.cellProperties[data.name] = data.value;
|
|
||||||
},
|
|
||||||
setCanvasWidth(state, data) {
|
|
||||||
state.canvasWidth = data;
|
|
||||||
},
|
|
||||||
setCanvasHeight(state, data) {
|
|
||||||
state.canvasHeight = data;
|
|
||||||
},
|
|
||||||
setRefreshRate(state, data) {
|
|
||||||
state.refreshRate = data;
|
|
||||||
},
|
|
||||||
setInitial1dState(state, data) {
|
|
||||||
state.initial1dState = data;
|
|
||||||
},
|
|
||||||
setActiveMenu(state, data) {
|
|
||||||
state.activeMenu = data;
|
|
||||||
},
|
|
||||||
setDrawingDirection(state, data) {
|
|
||||||
state.drawingDirection = data;
|
|
||||||
},
|
|
||||||
setLastBoard(state, data) {
|
|
||||||
state.lastBoard = data;
|
|
||||||
},
|
|
||||||
setCanvas(state, data) {
|
|
||||||
state.canvas = data;
|
|
||||||
},
|
|
||||||
setContext(state, data) {
|
|
||||||
state.ctx = data;
|
|
||||||
},
|
|
||||||
toggleDraw1d(state, data) {
|
|
||||||
state.draw1d = data;
|
|
||||||
},
|
|
||||||
toggleDraw2d(state, data) {
|
|
||||||
state.draw2d = data;
|
|
||||||
},
|
|
||||||
toggleDraw2dLast(state, data) {
|
|
||||||
state.draw2dLast = data;
|
|
||||||
},
|
|
||||||
toggleReset(state, data) {
|
|
||||||
state.reset = data;
|
|
||||||
},
|
|
||||||
canDraw(state, data) {
|
|
||||||
state.canDraw = data;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
getters: {
|
|
||||||
getCellProperties(state) {
|
|
||||||
return state.cellProperties;
|
|
||||||
},
|
|
||||||
get1dRules(state) {
|
|
||||||
return state.rules1d;
|
|
||||||
},
|
|
||||||
getRule1d(state) {
|
|
||||||
return state.rules1d;
|
|
||||||
},
|
|
||||||
getCanvasWidth(state) {
|
|
||||||
return state.canvasWidth;
|
|
||||||
},
|
|
||||||
getCanvasHeight(state) {
|
|
||||||
return state.canvasHeight;
|
|
||||||
},
|
|
||||||
getRefreshRate(state) {
|
|
||||||
return state.refreshRate;
|
|
||||||
},
|
|
||||||
getInitial1dState(state) {
|
|
||||||
return state.initial1dState;
|
|
||||||
},
|
|
||||||
getActiveMenu(state) {
|
|
||||||
return state.activeMenu;
|
|
||||||
},
|
|
||||||
getDrawingDirection(state) {
|
|
||||||
return state.drawingDirection;
|
|
||||||
},
|
|
||||||
getLastBoard(state) {
|
|
||||||
return state.lastBoard;
|
|
||||||
},
|
|
||||||
getDraw1d(state) {
|
|
||||||
return state.draw1d;
|
|
||||||
},
|
|
||||||
getDraw2d(state) {
|
|
||||||
return state.draw2d;
|
|
||||||
},
|
|
||||||
getDraw2dLast(state) {
|
|
||||||
return state.draw2dLast;
|
|
||||||
},
|
|
||||||
getReset(state) {
|
|
||||||
return state.reset;
|
|
||||||
},
|
|
||||||
getCanDraw(state) {
|
|
||||||
return state.canDraw;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
actions: {
|
|
||||||
draw1d({ commit }) {
|
|
||||||
commit("toggleDraw1d", true);
|
|
||||||
},
|
|
||||||
draw2d({ commit }) {
|
|
||||||
commit("canDraw", true);
|
|
||||||
commit("toggleDraw2d", true);
|
|
||||||
},
|
|
||||||
draw2dLast({ commit }) {
|
|
||||||
commit("canDraw", true);
|
|
||||||
commit("toggleDraw2dLast", true);
|
|
||||||
},
|
|
||||||
reset({ dispatch, commit }) {
|
|
||||||
dispatch("stop");
|
|
||||||
commit("toggleReset", true);
|
|
||||||
},
|
|
||||||
stop({ commit }) {
|
|
||||||
commit("toggleDraw1d", false);
|
|
||||||
commit("toggleDraw2d", false);
|
|
||||||
commit("toggleDraw2dLast", false);
|
|
||||||
commit("canDraw", false);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
modules: {},
|
|
||||||
});
|
|
62
src/stores/index.js
Normal file
62
src/stores/index.js
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
import { defineStore } from "pinia";
|
||||||
|
|
||||||
|
export const globalStore = defineStore("globalStore", {
|
||||||
|
state: () => {
|
||||||
|
return {
|
||||||
|
rules1d: {
|
||||||
|
name: "rule 73",
|
||||||
|
rules: {
|
||||||
|
111: 0,
|
||||||
|
110: 1,
|
||||||
|
101: 0,
|
||||||
|
100: 0,
|
||||||
|
"011": 1,
|
||||||
|
"010": 0,
|
||||||
|
"001": 0,
|
||||||
|
"000": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
cellProperties: {
|
||||||
|
size: 3,
|
||||||
|
liveColor: "#000000",
|
||||||
|
deadColor: "#F5F5F5",
|
||||||
|
},
|
||||||
|
canvasWidth: 0,
|
||||||
|
canvasHeight: 0,
|
||||||
|
boardWidth: 0,
|
||||||
|
boardHeight: 0,
|
||||||
|
refreshRate: 300,
|
||||||
|
initial1dState: "onecell",
|
||||||
|
drawingDirection: "y",
|
||||||
|
lastBoard: {},
|
||||||
|
draw1d: false,
|
||||||
|
draw2d: false,
|
||||||
|
draw2dLast: false,
|
||||||
|
reset: false,
|
||||||
|
canDraw: true,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
toggleDraw1d() {
|
||||||
|
this.draw1d = true;
|
||||||
|
},
|
||||||
|
toggleDraw2d() {
|
||||||
|
this.canDraw = true;
|
||||||
|
this.draw2d = true;
|
||||||
|
},
|
||||||
|
toggleDraw2dLast() {
|
||||||
|
this.canDraw = true;
|
||||||
|
this.draw2dLast = true;
|
||||||
|
},
|
||||||
|
toggleReset() {
|
||||||
|
this.toggleStop();
|
||||||
|
this.reset = true;
|
||||||
|
},
|
||||||
|
toggleStop() {
|
||||||
|
this.draw1d = false;
|
||||||
|
this.draw2d = false;
|
||||||
|
this.draw2dLast = false;
|
||||||
|
this.canDraw = false;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
@ -1,13 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
configureWebpack: {
|
|
||||||
devServer: {
|
|
||||||
overlay: {
|
|
||||||
warnings: true,
|
|
||||||
errors: true,
|
|
||||||
},
|
|
||||||
watchOptions: {
|
|
||||||
ignored: [/node_modules/, /public/, /\.#/],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
Loading…
Reference in New Issue
Block a user