Added documentation about switching "pages" in p5
This commit is contained in:
38
teamdocumentatie/switchcanvas.js
Normal file
38
teamdocumentatie/switchcanvas.js
Normal 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);
|
||||
}
|
Reference in New Issue
Block a user