Compare commits
2 Commits
1204ac01c3
...
5c21fb2ac3
Author | SHA1 | Date | |
---|---|---|---|
5c21fb2ac3 | |||
2c69840d6f |
37
src/App.vue
37
src/App.vue
@ -10,17 +10,22 @@
|
|||||||
<MainMenu v-if="mainMenu || windowWidth >= 800" />
|
<MainMenu v-if="mainMenu || windowWidth >= 800" />
|
||||||
<CanvasBoard />
|
<CanvasBoard />
|
||||||
</div>
|
</div>
|
||||||
|
<MenuReset row-title="" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import MainMenu from "./components/MainMenu.vue";
|
import MainMenu from "./components/MainMenu.vue";
|
||||||
import CanvasBoard from "./components/CanvasBoard.vue";
|
import CanvasBoard from "./components/CanvasBoard.vue";
|
||||||
|
import MenuReset from "./components/MenuReset.vue";
|
||||||
|
import { mapWritableState, mapActions } from "pinia";
|
||||||
|
import { globalStore } from "./stores/index.js";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "App",
|
name: "App",
|
||||||
components: {
|
components: {
|
||||||
MainMenu,
|
MainMenu,
|
||||||
|
MenuReset,
|
||||||
CanvasBoard,
|
CanvasBoard,
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
@ -29,22 +34,35 @@
|
|||||||
windowWidth: window.innerWidth,
|
windowWidth: window.innerWidth,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
computed: {
|
||||||
toggleMainMenu() {
|
...mapWritableState(globalStore, {
|
||||||
this.mainMenu = !this.mainMenu;
|
canvasWidth: "canvasWidth",
|
||||||
},
|
canvasHeight: "canvasHeight",
|
||||||
onResize() {
|
}),
|
||||||
this.windowWidth = window.innerWidth;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
window.addEventListener("resize", this.onResize);
|
window.addEventListener("resize", this.onResize);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeUnmount() {
|
||||||
window.removeEventListener("resize", this.onResize);
|
window.removeEventListener("resize", this.onResize);
|
||||||
},
|
},
|
||||||
|
methods: {
|
||||||
|
...mapActions(globalStore, ["setBoardWidth", "setBoardHeight"]),
|
||||||
|
toggleMainMenu() {
|
||||||
|
this.mainMenu = !this.mainMenu;
|
||||||
|
},
|
||||||
|
onResize() {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.windowWidth = window.innerWidth;
|
||||||
|
this.canvasWidth = window.innerWidth;
|
||||||
|
this.canvasHeight = window.innerHeight;
|
||||||
|
this.setBoardWidth();
|
||||||
|
this.setBoardHeight();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -118,8 +136,9 @@
|
|||||||
h1 {
|
h1 {
|
||||||
font-size: medium;
|
font-size: medium;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-around;
|
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 0 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#burger-toggle {
|
#burger-toggle {
|
||||||
|
@ -38,6 +38,8 @@
|
|||||||
getDraw1d: "draw1d",
|
getDraw1d: "draw1d",
|
||||||
getDraw2d: "draw2d",
|
getDraw2d: "draw2d",
|
||||||
getDraw2dLast: "draw2dLast",
|
getDraw2dLast: "draw2dLast",
|
||||||
|
boardWidth: "boardWidth",
|
||||||
|
boardHeight: "boardHeight",
|
||||||
}),
|
}),
|
||||||
...mapWritableState(globalStore, {
|
...mapWritableState(globalStore, {
|
||||||
lastBoard: "lastBoard",
|
lastBoard: "lastBoard",
|
||||||
@ -45,12 +47,6 @@
|
|||||||
canvasHeight: "canvasHeight",
|
canvasHeight: "canvasHeight",
|
||||||
getReset: "reset",
|
getReset: "reset",
|
||||||
}),
|
}),
|
||||||
boardWidth: function () {
|
|
||||||
return Math.floor(this.canvasWidth / this.cellProperties.size);
|
|
||||||
},
|
|
||||||
boardHeight: function () {
|
|
||||||
return Math.floor(this.canvasHeight / this.cellProperties.size);
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
getDraw1d(value) {
|
getDraw1d(value) {
|
||||||
@ -71,9 +67,15 @@
|
|||||||
this.ctx = this.canvas.getContext("2d");
|
this.ctx = this.canvas.getContext("2d");
|
||||||
this.canvasWidth = this.canvas.parentElement.clientWidth;
|
this.canvasWidth = this.canvas.parentElement.clientWidth;
|
||||||
this.canvasHeight = this.canvas.parentElement.clientHeight;
|
this.canvasHeight = this.canvas.parentElement.clientHeight;
|
||||||
|
this.setBoardWidth();
|
||||||
|
this.setBoardHeight();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(globalStore, ["toggleStop"]),
|
...mapActions(globalStore, [
|
||||||
|
"toggleStop",
|
||||||
|
"setBoardWidth",
|
||||||
|
"setBoardHeight",
|
||||||
|
]),
|
||||||
drawCanvas(board) {
|
drawCanvas(board) {
|
||||||
const props = this.cellProperties;
|
const props = this.cellProperties;
|
||||||
board.map((row, y) => {
|
board.map((row, y) => {
|
||||||
|
@ -1,30 +1,17 @@
|
|||||||
<template>
|
<template>
|
||||||
<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 empty board</label>
|
||||||
<input type="button" value="start" @click="toggleDraw2dLast()" />
|
|
||||||
</div>
|
|
||||||
<div class="form-field">
|
|
||||||
<input
|
<input
|
||||||
type="button"
|
type="button"
|
||||||
name="start2d"
|
name="start2d"
|
||||||
value="start"
|
value="start"
|
||||||
@click="toggleDraw2d()"
|
@click="toggleDraw2d()"
|
||||||
/>
|
/>
|
||||||
<input
|
</div>
|
||||||
type="button"
|
<div class="form-field">
|
||||||
name="stop"
|
<label>Start from last result</label>
|
||||||
class="stop"
|
<input type="button" value="start" @click="toggleDraw2dLast()" />
|
||||||
value="stop"
|
|
||||||
@click="toggleStop()"
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
type="button"
|
|
||||||
name="reset"
|
|
||||||
class="reset"
|
|
||||||
value="reset"
|
|
||||||
@click="toggleReset()"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</MenuRow>
|
</MenuRow>
|
||||||
</template>
|
</template>
|
||||||
@ -40,12 +27,7 @@
|
|||||||
MenuRow,
|
MenuRow,
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(globalStore, [
|
...mapActions(globalStore, ["toggleDraw2dLast", "toggleDraw2d"]),
|
||||||
"toggleDraw2d",
|
|
||||||
"toggleDraw2dLast",
|
|
||||||
"toggleReset",
|
|
||||||
"toggleStop",
|
|
||||||
]),
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -64,13 +64,6 @@
|
|||||||
</form>
|
</form>
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
<input type="button" name="start" value="start" @click="toggleDraw1d()" />
|
<input type="button" name="start" value="start" @click="toggleDraw1d()" />
|
||||||
<input
|
|
||||||
type="button"
|
|
||||||
name="reset"
|
|
||||||
class="reset"
|
|
||||||
value="reset"
|
|
||||||
@click="toggleReset"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</MenuRow>
|
</MenuRow>
|
||||||
</template>
|
</template>
|
||||||
@ -108,7 +101,7 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(globalStore, ["toggleDraw1d", "toggleReset"]),
|
...mapActions(globalStore, ["toggleDraw1d"]),
|
||||||
copyRules() {
|
copyRules() {
|
||||||
const rules = JSON.stringify(this.rules);
|
const rules = JSON.stringify(this.rules);
|
||||||
navigator.clipboard.writeText(rules);
|
navigator.clipboard.writeText(rules);
|
||||||
|
36
src/components/MenuReset.vue
Normal file
36
src/components/MenuReset.vue
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<template>
|
||||||
|
<div class="form-field">
|
||||||
|
<input
|
||||||
|
type="button"
|
||||||
|
name="stop"
|
||||||
|
class="stop"
|
||||||
|
value="stop"
|
||||||
|
@click="toggleStop()"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="button"
|
||||||
|
name="reset"
|
||||||
|
class="reset"
|
||||||
|
value="reset"
|
||||||
|
@click="toggleReset()"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
import { mapActions } from "pinia";
|
||||||
|
import { globalStore } from "../stores/index.js";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "MenuReset",
|
||||||
|
methods: {
|
||||||
|
...mapActions(globalStore, ["toggleReset", "toggleStop"]),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
<style scoped>
|
||||||
|
.form-field {
|
||||||
|
display: flex;
|
||||||
|
margin: 5px;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
</style>
|
@ -37,6 +37,14 @@ export const globalStore = defineStore("globalStore", {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
setBoardWidth() {
|
||||||
|
this.boardWidth = Math.floor(this.canvasWidth / this.cellProperties.size);
|
||||||
|
},
|
||||||
|
setBoardHeight() {
|
||||||
|
this.boardHeight = Math.floor(
|
||||||
|
this.canvasHeight / this.cellProperties.size
|
||||||
|
);
|
||||||
|
},
|
||||||
toggleDraw1d() {
|
toggleDraw1d() {
|
||||||
this.draw1d = true;
|
this.draw1d = true;
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user