add setpos() command
This commit is contained in:
parent
02a08761da
commit
40fb446348
18
lib/plogo.js
18
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);
|
||||
|
|
Loading…
Reference in New Issue