xxxxxxxxxx
44
// simple tool for free hand drawing,
// recording shape commands (press any key to
// generate the code.)
let buf = "";
function setup() {
createCanvas(600, 600);
}
function draw() {
// background(220);
}
function mousePressed(){
bufAdd("beginShape();");
}
let lmx = null, lmy = null;
function mouseDragged(){
if(lmx !== null && lmy !== null && (lmx != mouseX || lmy != mouseY)) {
line(lmx,lmy,mouseX,mouseY);
bufAdd(`vertex(${mouseX},${mouseY});`);
}
lmx = mouseX; lmy = mouseY;
}
function mouseReleased(){
bufAdd("endShape(CLOSE);\n\n\n");
lmx = null; lmy = null;
}
function bufAdd(msg){
buf += msg;
buf += "\n";
}
function keyPressed(){
console.log(buf);
}