Added documentation about switching "pages" in p5

This commit is contained in:
sam
2024-01-09 14:05:45 +01:00
parent 5a691023b1
commit 9632664614

View File

@@ -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);
}