From 477c24f7c0d11c2302404c7327c195296a1aedc2 Mon Sep 17 00:00:00 2001 From: sam Date: Tue, 23 Jan 2024 14:10:07 +0100 Subject: [PATCH] Added more documenattion for better soluction --- docs/documentatie/Documentatie game.md | 47 +++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/docs/documentatie/Documentatie game.md b/docs/documentatie/Documentatie game.md index 353695f..de29a69 100644 --- a/docs/documentatie/Documentatie game.md +++ b/docs/documentatie/Documentatie game.md @@ -40,4 +40,49 @@ function canvas2(){ fill(255, 0, 0) circle (300, 200, 50); } -``` \ No newline at end of file +``` + +Wat ik later heb gevonden is een betere manier waarbij je een variabel een int maakt en dan een switch statement gebruikt. Dit is een stuk beter dan wat ik heb gedaan. Hieronder staat de code: +```js + +let canvasSwitch = 0; + +function setup(){ + createCanvas(400, 400); + } + +function draw(){ + //draw a background every frame + background(220) + //switch canvas when spacebar is pressed + if (canvasSwitch == 0){ + canvas1(); + } + + if (canvasSwitch == 1){ + canvas2(); + } + +} + +function keyPressed(){ + if (keyCode == 32){ // 32 is the keyCode for the space bar + canvasSwitch = 1 + } + if (keyCode == 16){ // 16 is the keyCode for the Shift key + canvasSwitch = 0 + } +} + +//draw a yellow circle on canvas 1 +function canvas1(){ + fill(255, 255, 0) + circle (200, 200, 50); +} + +//draw a red circle on canvas 2 +function canvas2(){ + fill(255, 0, 0) + circle (300, 200, 50); +} +```