Compare commits
2 Commits
b87993701d
...
40fb446348
Author | SHA1 | Date |
---|---|---|
lee2sman | 40fb446348 | |
lee2sman | 02a08761da |
|
@ -39,6 +39,11 @@ right(Δ)
|
|||
```
|
||||
turns Δ degrees to the right
|
||||
|
||||
```
|
||||
setpos(x,y)
|
||||
```
|
||||
moves turtle to x,y pixel coordinate. 0,0 is top left of window.
|
||||
|
||||
### Drawing
|
||||
|
||||
```
|
||||
|
|
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