diff --git a/lib/plogo.js b/lib/plogo.js index ff2c70d..583f5d8 100644 --- a/lib/plogo.js +++ b/lib/plogo.js @@ -17,6 +17,24 @@ function resetDefaults() { x = width / 2; //start turtle in center y = height / 2; } +function setpos(_newX, _newY, startx = x, starty = y) { + let newX = _newX; + let newY = _newY; + + if (drawing) { + line(startx, starty, newX, newY); + } + x = newX; + y = newY; + + try { + if ((_newX == "") || (_newY == "")) throw "is missing input x,y coordinates"; + if (isNaN(_newX) || (isNaN(_newY))) throw "requires: x,y input coordinates"; + if ((_newX < 0) || (_newY < 0) || (_newX > windowWidth) || (_newY > windowHeight)) throw "drawing offscreen"; + } catch (err) { + console.log("Error: setpos " + err); + } +} function forward(d, startx = x, starty = y, _angle = 360 - angle) { let newX = startx + d * sin(_angle); let newY = starty + d * cos(_angle);