pen up/pen down

This commit is contained in:
Chris Wanstrath 2025-12-12 08:39:35 -08:00
parent 6e065febaf
commit 5c28ec18e8
3 changed files with 12 additions and 2 deletions

View File

@ -1,5 +1,6 @@
{ {
"lockfileVersion": 1, "lockfileVersion": 1,
"configVersion": 0,
"workspaces": { "workspaces": {
"": { "": {
"name": "fin", "name": "fin",

View File

@ -196,6 +196,14 @@ class Turtle {
turtleCtx.restore() turtleCtx.restore()
} }
pen(dir: string) {
switch (dir) {
case 'up': this.penup(); break
case 'down': this.pendown(); break
default: throw "pen only accepts up or down"
}
}
penup() { penup() {
this.penDown = false this.penDown = false
} }
@ -254,6 +262,7 @@ const globals = {
back: async (n: number) => await turtle.back(n), back: async (n: number) => await turtle.back(n),
left: async (n: number) => await turtle.left(n), left: async (n: number) => await turtle.left(n),
right: async (n: number) => await turtle.right(n), right: async (n: number) => await turtle.right(n),
pen: (dir) => turtle.pen(dir),
penup: () => turtle.penup(), penup: () => turtle.penup(),
pendown: () => turtle.pendown(), pendown: () => turtle.pendown(),
setcolor: (n: number) => turtle.setcolor(n), setcolor: (n: number) => turtle.setcolor(n),