2022-01-09 11:47:18 +01:00
|
|
|
<template>
|
|
|
|
<MenuRow row-title="Elementary Cellular Automata">
|
|
|
|
<form>
|
2022-01-11 13:16:42 +01:00
|
|
|
<div class="form-field">
|
2022-12-01 12:03:34 +01:00
|
|
|
<label>
|
|
|
|
Initial state presets
|
2022-11-29 17:31:01 +01:00
|
|
|
<br />
|
2022-01-11 13:16:42 +01:00
|
|
|
<select
|
2022-12-01 12:03:34 +01:00
|
|
|
name="initialStates"
|
|
|
|
:value="initialState"
|
|
|
|
@input="updateInitialState"
|
2022-01-11 13:16:42 +01:00
|
|
|
>
|
|
|
|
<option
|
2022-12-01 20:37:03 +01:00
|
|
|
v-for="(state, index) in initialStates"
|
|
|
|
:key="'initial-state-elementary' + index"
|
2022-01-11 13:16:42 +01:00
|
|
|
:value="state.id"
|
2022-11-29 17:31:01 +01:00
|
|
|
>
|
|
|
|
{{ state.name }}
|
2022-01-11 13:16:42 +01:00
|
|
|
</option>
|
|
|
|
</select>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div class="form-field">
|
|
|
|
<label>Rules</label>
|
|
|
|
</div>
|
2022-01-12 19:10:16 +01:00
|
|
|
<div class="form-field">
|
2022-11-29 17:31:01 +01:00
|
|
|
<label
|
2022-12-01 20:37:03 +01:00
|
|
|
>Rules presets
|
2022-11-29 17:31:01 +01:00
|
|
|
<br />
|
2022-12-01 12:03:34 +01:00
|
|
|
<select
|
|
|
|
name="ruleset-elementary"
|
|
|
|
:value="rules.name"
|
|
|
|
@input="updateRules"
|
|
|
|
>
|
2022-01-12 19:10:16 +01:00
|
|
|
<option
|
2022-12-01 20:37:03 +01:00
|
|
|
v-for="(ruleset, index) in presetRules"
|
|
|
|
:key="'ruleset-preset-elementary-' + index"
|
2022-12-01 12:03:34 +01:00
|
|
|
:value="ruleset.name"
|
2022-11-29 17:31:01 +01:00
|
|
|
>
|
2022-12-01 12:03:34 +01:00
|
|
|
{{ ruleset.name }}
|
2022-01-12 19:10:16 +01:00
|
|
|
</option>
|
|
|
|
</select>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div class="form-field">
|
2022-12-01 12:03:34 +01:00
|
|
|
<a style="cursor: pointer" @click="copyRules">copy rules</a>
|
2022-01-12 19:10:16 +01:00
|
|
|
</div>
|
2022-01-10 11:13:44 +01:00
|
|
|
<div
|
2022-12-01 20:37:03 +01:00
|
|
|
v-for="(rule, name, index) in rules.rules"
|
|
|
|
:key="'rule-' + index"
|
2022-01-10 11:13:44 +01:00
|
|
|
class="form-field"
|
|
|
|
>
|
2022-11-29 17:31:01 +01:00
|
|
|
<label
|
2022-12-01 20:37:03 +01:00
|
|
|
>{{ name }}
|
2022-01-09 11:47:18 +01:00
|
|
|
<input
|
2022-01-12 19:10:16 +01:00
|
|
|
:value="rule"
|
2022-01-09 11:47:18 +01:00
|
|
|
type="checkbox"
|
2022-01-12 19:10:16 +01:00
|
|
|
:name="name"
|
|
|
|
:checked="rule"
|
2022-12-01 12:03:34 +01:00
|
|
|
@input="updateSingleRule"
|
2022-11-29 17:31:01 +01:00
|
|
|
/>
|
2022-01-09 11:47:18 +01:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
<div class="form-field">
|
2022-11-29 17:31:01 +01:00
|
|
|
<input type="button" name="start" value="start" @click="draw1d" />
|
2022-01-09 11:47:18 +01:00
|
|
|
<input
|
|
|
|
type="button"
|
|
|
|
name="reset"
|
|
|
|
class="reset"
|
|
|
|
value="reset"
|
2022-01-10 11:13:44 +01:00
|
|
|
@click="reset()"
|
2022-11-29 17:31:01 +01:00
|
|
|
/>
|
2022-01-09 11:47:18 +01:00
|
|
|
</div>
|
|
|
|
</MenuRow>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-12-01 20:37:03 +01:00
|
|
|
import { mapGetters } from "vuex";
|
|
|
|
import MenuRow from "./MenuRow.vue";
|
|
|
|
export default {
|
|
|
|
name: "MenuElementaryCA",
|
|
|
|
components: {
|
|
|
|
MenuRow,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
// TODO: Why not a getter in the store?
|
|
|
|
return {
|
|
|
|
presetRules: [
|
|
|
|
{
|
|
|
|
name: "rule 73",
|
|
|
|
rules: {
|
|
|
|
100: 0,
|
|
|
|
101: 0,
|
2022-12-01 12:03:34 +01:00
|
|
|
110: 1,
|
|
|
|
111: 0,
|
|
|
|
"011": 1,
|
|
|
|
"010": 0,
|
|
|
|
"001": 0,
|
|
|
|
"000": 1,
|
|
|
|
},
|
2022-12-01 20:37:03 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "rule 86",
|
|
|
|
rules: {
|
2022-12-01 12:03:34 +01:00
|
|
|
100: 1,
|
|
|
|
101: 0,
|
|
|
|
110: 0,
|
|
|
|
111: 1,
|
|
|
|
"011": 0,
|
|
|
|
"010": 1,
|
|
|
|
"001": 0,
|
|
|
|
"000": 1,
|
|
|
|
},
|
2022-12-01 20:37:03 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "rule 90",
|
|
|
|
rules: {
|
|
|
|
100: 1,
|
|
|
|
101: 0,
|
|
|
|
110: 1,
|
|
|
|
111: 0,
|
|
|
|
"011": 0,
|
|
|
|
"010": 0,
|
|
|
|
"001": 1,
|
|
|
|
"000": 0,
|
2022-12-01 12:03:34 +01:00
|
|
|
},
|
2022-12-01 20:37:03 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "rule 45?",
|
|
|
|
rules: {
|
2022-12-01 12:03:34 +01:00
|
|
|
100: 0,
|
|
|
|
101: 0,
|
|
|
|
110: 1,
|
|
|
|
111: 0,
|
|
|
|
"011": 1,
|
|
|
|
"010": 0,
|
|
|
|
"001": 1,
|
|
|
|
"000": 1,
|
|
|
|
},
|
2022-12-01 20:37:03 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "rule 54?",
|
|
|
|
rules: {
|
2022-12-01 12:03:34 +01:00
|
|
|
100: 1,
|
|
|
|
101: 0,
|
|
|
|
110: 1,
|
|
|
|
111: 1,
|
|
|
|
"011": 0,
|
|
|
|
"010": 1,
|
|
|
|
"001": 1,
|
|
|
|
"000": 0,
|
|
|
|
},
|
2022-12-01 20:37:03 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unknown rule",
|
|
|
|
rules: {
|
|
|
|
100: 0,
|
|
|
|
101: 0,
|
|
|
|
110: 0,
|
|
|
|
111: 1,
|
|
|
|
"011": 0,
|
|
|
|
"010": 0,
|
|
|
|
"001": 1,
|
|
|
|
"000": 1,
|
2022-12-01 12:03:34 +01:00
|
|
|
},
|
2022-12-01 20:37:03 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
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: {
|
|
|
|
...mapGetters({
|
|
|
|
initialState: "getInitial1dState",
|
|
|
|
rules: "get1dRules",
|
|
|
|
}),
|
|
|
|
rules1dFileName() {
|
|
|
|
return (
|
|
|
|
Object.keys(this.rules)
|
|
|
|
.map((index) => {
|
|
|
|
return this.rules[index];
|
|
|
|
})
|
|
|
|
.join("_") + ".json"
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
copyRules() {
|
|
|
|
const rules = JSON.stringify(this.rules);
|
|
|
|
navigator.clipboard.writeText(rules);
|
|
|
|
},
|
|
|
|
isCurrentPreset(event) {
|
|
|
|
const elem = event.target;
|
|
|
|
return this.initialState === elem.value;
|
2022-01-12 19:10:16 +01:00
|
|
|
},
|
2022-12-01 20:37:03 +01:00
|
|
|
updateSingleRule(event) {
|
|
|
|
const elem = event.target;
|
|
|
|
const value = elem.checked ? 1 : 0;
|
|
|
|
const data = { rule: elem.name, value: value };
|
|
|
|
this.$store.commit("update1dSingleRule", data);
|
2022-01-12 19:10:16 +01:00
|
|
|
},
|
2022-12-01 20:37:03 +01:00
|
|
|
updateRules(event) {
|
|
|
|
// TODO : change this, awfully confusing
|
|
|
|
const elem = event.target;
|
|
|
|
const name = elem.value;
|
|
|
|
const rules = this.presetRules.find((ruleset) => {
|
|
|
|
return ruleset.name === name;
|
|
|
|
});
|
|
|
|
Object.keys(rules.rules).map((value) => {
|
|
|
|
const data = { name: name, rule: value, value: rules.rules[value] };
|
2022-11-29 17:31:01 +01:00
|
|
|
this.$store.commit("update1dSingleRule", data);
|
2022-12-01 20:37:03 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
updateInitialState(event) {
|
|
|
|
const elem = event.target;
|
|
|
|
this.$store.commit("setInitial1dState", elem.value);
|
|
|
|
},
|
|
|
|
draw1d() {
|
|
|
|
/* this.$store.commit("setDrawingStatus", 1); */
|
|
|
|
this.$store.dispatch("draw1d");
|
|
|
|
},
|
|
|
|
reset() {
|
|
|
|
this.$store.dispatch("reset");
|
2022-01-10 11:13:44 +01:00
|
|
|
},
|
2022-12-01 20:37:03 +01:00
|
|
|
},
|
|
|
|
};
|
2022-01-09 11:47:18 +01:00
|
|
|
</script>
|
2022-01-12 19:10:16 +01:00
|
|
|
<style>
|
2022-12-01 20:37:03 +01:00
|
|
|
.menu-row a {
|
|
|
|
color: white;
|
|
|
|
font-weight: bold;
|
|
|
|
text-decoration: none;
|
|
|
|
font-size: small;
|
|
|
|
}
|
2022-01-12 19:10:16 +01:00
|
|
|
</style>
|