diff --git a/src/web/thurtle/draw.tsx b/src/web/thurtle/draw.tsx index d6a602e..e3b53ab 100644 --- a/src/web/thurtle/draw.tsx +++ b/src/web/thurtle/draw.tsx @@ -11,6 +11,7 @@ enum PenState { type Path = { strokeWidth?: number; + strokeColor?: number; d: string[]; }; @@ -87,6 +88,11 @@ export default async function draw({ paths.push({ d: [`M ${position.x} ${position.y}`], strokeWidth: s }); }); + forth.bind("setpencolor", (stack) => { + const s = stack.pop(); + paths.push({ d: [`M ${position.x} ${position.y}`], strokeColor: s }); + }); + forth.bind("setxy", (stack) => { const y = stack.pop(); const x = stack.pop(); @@ -131,12 +137,17 @@ export default async function draw({ ); pathsEl.innerHTML = ""; + let strokeWidth = 5; + let strokeColor = 0; for (const path of paths) { + strokeColor = path.strokeColor ?? strokeColor; + strokeWidth = path.strokeWidth ?? strokeWidth; const pathEl = ( ); pathsEl.appendChild(pathEl); diff --git a/src/web/thurtle/jsx.ts b/src/web/thurtle/jsx.ts index 16a0b18..132e5de 100644 --- a/src/web/thurtle/jsx.ts +++ b/src/web/thurtle/jsx.ts @@ -25,6 +25,7 @@ declare global { }; path: JSXElement & { xmlns: "http://www.w3.org/2000/svg"; + stroke?: string; d?: string; }; g: JSXElement> & { diff --git a/src/web/thurtle/thurtle.css b/src/web/thurtle/thurtle.css index 06f6943..7312a11 100644 --- a/src/web/thurtle/thurtle.css +++ b/src/web/thurtle/thurtle.css @@ -31,7 +31,6 @@ } .world path { - stroke: black; fill: white; fill-opacity: 0; } diff --git a/src/web/thurtle/thurtle.fs b/src/web/thurtle/thurtle.fs index 1a050f9..1744a08 100644 --- a/src/web/thurtle/thurtle.fs +++ b/src/web/thurtle/thurtle.fs @@ -7,5 +7,6 @@ : HIDETURTLE ( -- ) 0 S" turtle" SCALL ; : SHOWTURTLE ( -- ) 1 S" turtle" SCALL ; : SETPENSIZE ( n -- ) S" setpensize" SCALL ; +: SETPENCOLOR ( n -- ) S" setpencolor" SCALL ; : SETXY ( n1 n2 -- ) S" setxy" SCALL ; -: SETHEADING ( n -- ) S" setheading" SCALL ; \ No newline at end of file +: SETHEADING ( n -- ) S" setheading" SCALL ; diff --git a/src/web/thurtle/thurtle.tsx b/src/web/thurtle/thurtle.tsx index c7ea82c..33c9e96 100644 --- a/src/web/thurtle/thurtle.tsx +++ b/src/web/thurtle/thurtle.tsx @@ -356,6 +356,10 @@ const rootEl = ( SETPENSIZE ( n -- ): Set the width of the drawed strokes to n (default: 5). +
  • + SETPENCOLOR ( n -- ): Set the color of the drawed + strokes to RGB value n (default: 0). +
  • HIDETURTLE ( -- ): Hide the turtle.