From 7aa1dc90cd96e5ef5c6145de406f827165cf4129 Mon Sep 17 00:00:00 2001 From: waltem01 Date: Sun, 7 Aug 2022 15:32:04 +0200 Subject: [PATCH] draw on screen --- Webserver/src/routes/+page.svelte | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Webserver/src/routes/+page.svelte b/Webserver/src/routes/+page.svelte index 7f1ff70..22a7f4a 100644 --- a/Webserver/src/routes/+page.svelte +++ b/Webserver/src/routes/+page.svelte @@ -98,7 +98,7 @@ pixelColor[2] = parseInt((formData.get('b') as string) ?? '255'); } - function setColor(event: MouseEvent) { + async function setMousePixel(event: MouseEvent) { if (!mousePressed) return; const parent = event.target as HTMLTableCellElement; @@ -106,6 +106,18 @@ const y = parseInt(parent.parentElement?.dataset.y ?? '0'); matrix[y][x].color = colorToHex(); + + const fdata = new FormData(); + fdata.append('x', x.toString()); + fdata.append('y', y.toString()); + + const response = await fetch('http://localhost:8080/pixel', { + method: 'POST', + mode: 'cors', + body: fdata + }); + const mdata = (await response.json()) as MatrixResponse; + if (!mdata.success) alert("Error while processing 'pixel'!"); } function colorToHex(): string { @@ -364,7 +376,7 @@ min="0" max="191" step="1" - value="0" + value="8" required /> @@ -376,7 +388,7 @@ min="0" max="191" step="1" - value="0" + value="9" required /> {/each}