From 96326646145a6d8e14ccafa33b50fe2c3d336967 Mon Sep 17 00:00:00 2001 From: sam Date: Tue, 9 Jan 2024 14:05:45 +0100 Subject: [PATCH] Added documentation about switching "pages" in p5 --- teamdocumentatie/switchcanvas.js | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 teamdocumentatie/switchcanvas.js diff --git a/teamdocumentatie/switchcanvas.js b/teamdocumentatie/switchcanvas.js new file mode 100644 index 0000000..80b3f31 --- /dev/null +++ b/teamdocumentatie/switchcanvas.js @@ -0,0 +1,38 @@ +let canvasSwitch = true; + +function setup(){ + createCanvas(400, 400); + } + +function draw(){ + //draw a backgroun every frame + background(220) + //switch canvas when spacebar is pressed + if (canvasSwitch == false){ + canvas1(); + } + + if (canvasSwitch == true){ + canvas2(); + } + +} + +function keyPressed(){ + if (keyCode === 32){ // 32 is the keyCode for the space bar + //if canvasSwitch is true, set it to false, vice versa + canvasSwitch = !canvasSwitch; + } +} + +//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); +} \ No newline at end of file