function
setup() {
createCanvas(400, 300);
createBtn = createButton(
"Create Canvas"
);
createBtn.position(30, 20);
createBtn.mouseClicked(createDrawArea);
removeBtn = createButton(
"Remove Canvas"
);
removeBtn.position(30, 50);
removeBtn.mouseClicked(removeDrawArea);
}
function
removeDrawArea() {
try
{
noCanvas();
}
catch
(e) {
print(
"No canvas found to remove"
);
print(e);
}
}
function
createDrawArea() {
createCanvas(400, 300);
}
function
draw() {
clear();
background(
"green"
);
textSize(20);
text(
"This is the canvas area"
, 50, 130);
text(
"Canvas height: "
+ height, 50, 150);
text(
"Canvas width: "
+ width, 50, 170);
}