configurable refresh rate for 2d CA

This commit is contained in:
Ali Gator 2022-01-10 20:49:09 +01:00
parent 980be551c1
commit 6f1e813316
3 changed files with 30 additions and 3 deletions

View File

@ -26,7 +26,8 @@ export default {
rules: 'getRuleSet1d', rules: 'getRuleSet1d',
drawing: 'isDrawing', drawing: 'isDrawing',
canvasWidth: 'getCanvasWidth', canvasWidth: 'getCanvasWidth',
canvasHeight: 'getCanvasHeight' canvasHeight: 'getCanvasHeight',
refreshRate: 'getRefreshRate'
}) })
}, },
mounted() { mounted() {
@ -82,7 +83,7 @@ export default {
if (this.drawing === 0) return if (this.drawing === 0) return
const newBoard = evolve2d(b, conwayRules) const newBoard = evolve2d(b, conwayRules)
this.drawCanvas(b, this.cellProperties) this.drawCanvas(b, this.cellProperties)
await sleep(300) await sleep(this.refreshRate)
draw2dNext(newBoard) draw2dNext(newBoard)
} }
return draw2dNext(board) return draw2dNext(board)

View File

@ -22,6 +22,20 @@
@input="updateCanvasHeight" @input="updateCanvasHeight"
> >
</div> </div>
<div class="form-field">
<label for="live">Refresh Rate (ms)</label>
</div>
<div class="form-field">
<input
id="refreshRate"
name="refreshRate"
type="number"
min="100"
step="100"
:value="refreshRate"
@input="updateRefreshRate"
>
</div>
</form> </form>
</MenuRow> </MenuRow>
</template> </template>
@ -37,7 +51,8 @@ export default {
computed: { computed: {
...mapGetters({ ...mapGetters({
canvasWidth: 'getCanvasWidth', canvasWidth: 'getCanvasWidth',
canvasHeight: 'getCanvasHeight' canvasHeight: 'getCanvasHeight',
refreshRate: 'getRefreshRate'
}) })
}, },
methods: { methods: {
@ -48,6 +63,10 @@ export default {
updateCanvasWidth: function(event) { updateCanvasWidth: function(event) {
const elem = event.target const elem = event.target
this.$store.commit('setCanvasWidth', elem.value) this.$store.commit('setCanvasWidth', elem.value)
},
updateRefreshRate: function(event) {
const elem = event.target
this.$store.commit('setRefreshRate', elem.value)
} }
} }
} }

View File

@ -23,6 +23,7 @@ export default new Vuex.Store({
}, },
canvasWidth: 1280, canvasWidth: 1280,
canvasHeight: 720, canvasHeight: 720,
refreshRate: 300
}, },
mutations: { mutations: {
update1dRules(state, data) { update1dRules(state, data) {
@ -39,6 +40,9 @@ export default new Vuex.Store({
}, },
setCanvasHeight(state, data) { setCanvasHeight(state, data) {
state.canvasHeight = data; state.canvasHeight = data;
},
setRefreshRate(state, data) {
state.refreshRate = data;
} }
}, },
getters: { getters: {
@ -59,6 +63,9 @@ export default new Vuex.Store({
}, },
getCanvasHeight(state) { getCanvasHeight(state) {
return state.canvasHeight return state.canvasHeight
},
getRefreshRate(state) {
return state.refreshRate
} }
}, },
actions: { actions: {