From aa65d4545177291b9e777d78e5c92ce3e29e00ff Mon Sep 17 00:00:00 2001 From: leomcelroy Date: Tue, 17 Oct 2023 01:50:55 -0400 Subject: [PATCH] WIP adding tailwind added fills --- astro/src/components/DropBox.tsx | 49 ++++++++++---------- astro/src/components/Preview.tsx | 38 +++++++++------- astro/src/components/Toolbar.tsx | 62 ++++++++++---------------- astro/src/lib/drawingToolkit/turtle.ts | 24 ++++++++-- astro/src/lib/run.ts | 10 ++++- astro/src/pages/test.astro | 10 ++++- 6 files changed, 107 insertions(+), 86 deletions(-) diff --git a/astro/src/components/DropBox.tsx b/astro/src/components/DropBox.tsx index 64f463d09..b7bfe75e8 100644 --- a/astro/src/components/DropBox.tsx +++ b/astro/src/components/DropBox.tsx @@ -9,29 +9,27 @@ export default function DropBox() { }, []) // Empty dependency array means this effect runs once after initial render return ( - <> - - - + ) } @@ -81,8 +79,9 @@ function addDragDrop() { window.addEventListener('dragover', function (evt) { droparea.classList.remove('hidden') pauseEvent(evt) - }) - ;['mouseout'].forEach(trigger => + }); + + ['mouseout'].forEach(trigger => window.addEventListener(trigger, function (evt) { droparea.classList.add('hidden') }) diff --git a/astro/src/components/Preview.tsx b/astro/src/components/Preview.tsx index 8ded4b231..82b9748f3 100644 --- a/astro/src/components/Preview.tsx +++ b/astro/src/components/Preview.tsx @@ -205,31 +205,37 @@ const _redraw = (canvas: HTMLCanvasElement) => { // draw turtles - ctx.strokeStyle = 'black' // turtle path // if(turtles.length === 0) return; const { panX, panY, scale } = panZoomParams - ctx.beginPath() for (const turtle of turtles) { + ctx.beginPath() + for (const polyline of turtle.path) { - const p = polyline.map(([x, y]) => [ - dpr * (panX + x * scale), - -(dpr * (-panY + y * scale)) - ]) - const paths = lineclip(p as Point[], [0, 0, width, height]) - - paths.forEach(p => { - for (let i = 0; i < p.length; i++) { - let [x, y] = p[i] - if (i === 0) ctx.moveTo(x, y) - else ctx.lineTo(x, y) - } + + // let paths = polyline.map(([x, y]) => [ + // dpr * (panX + x * scale), + // -(dpr * (-panY + y * scale)) + // ]) + + // paths = lineclip(paths, [0, 0, width, height]) + + polyline.forEach((p, i) => { + let [x, y] = p; + x = dpr * (panX + x * scale); + y = -(dpr * (-panY + y * scale)); + if (i === 0) ctx.moveTo(x, y) + else ctx.lineTo(x, y) }) + } - } + ctx.strokeStyle = turtle.style.stroke; + ctx.stroke(); - ctx.stroke() + ctx.fillStyle = turtle.style.fill; + if (turtle.style.fill !== "none") ctx.fill(); + } } diff --git a/astro/src/components/Toolbar.tsx b/astro/src/components/Toolbar.tsx index 24a904808..5fd3b3796 100644 --- a/astro/src/components/Toolbar.tsx +++ b/astro/src/components/Toolbar.tsx @@ -27,11 +27,7 @@ export default function Toolbar() { return (
-
+ -
+
@@ -99,9 +89,7 @@ function GitHubLink() { href="https://github.com/hackclub/blot/tree/main" rel="noreferrer" target="_blank"> -
- -
+
) @@ -187,8 +175,8 @@ function DownloadSVG() { return ` setHidden(true)}>
JSON.parse(JSON.stringify(obj)); + + const t = new Turtle(); + + t.path = copy(this.path); + t.drawing = copy(t.drawing); + t.position = copy(t.position); + t.angle = copy(t.angle); + t.path = copy(t.path); + t.style = copy(t.style); + + return t; } resample(resolution: number) { diff --git a/astro/src/lib/run.ts b/astro/src/lib/run.ts index 0603d1471..0541694cf 100644 --- a/astro/src/lib/run.ts +++ b/astro/src/lib/run.ts @@ -257,8 +257,14 @@ export default async function runCode(cached: boolean = false) { lerp(start: number, end: number, t: number) { return (1 - t) * start + t * end }, - drawTurtles: (...turtlesToDraw: Turtle[]) => { - turtlesToDraw.forEach(t => turtles.push(t)) + drawTurtles: (turtlesToDraw: Turtle[], style = {}) => { + turtlesToDraw.forEach(t => { + const temp = t.copy(); + if (style.fill === undefined) style.fill = "none"; + if (style.stroke === undefined) style.stroke = "black"; + temp.style = style; + turtles.push(temp); + }); }, setDocDimensions(w: number, h: number) { patchStore( diff --git a/astro/src/pages/test.astro b/astro/src/pages/test.astro index a0c20400c..600ddd73c 100644 --- a/astro/src/pages/test.astro +++ b/astro/src/pages/test.astro @@ -1 +1,9 @@ -nothing here \ No newline at end of file +nothing here + +
+ hello +
hello 1
+
hello 2
+
hello 3
+
hello 4
+
\ No newline at end of file