xxxxxxxxxx
26
let pg, canvas;
function setup() {
canvas = createCanvas(400, 400);
pg = createGraphics(400, 400);
}
function draw() {
background(220, 0, 0);
pg.circle(mouseX, mouseY, 100);
image(pg, 0, 0);
}
function keyPressed() {
if(key === 's' || key === 'a') {
const link = document.createElement('a');
link.download = 'canvas.png';
if(key === 's')
link.href = pg.elt.toDataURL();
else
link.href = canvas.elt.toDataURL();
link.click();
link.remove();
}
}