CAD
This commit is contained in:
@@ -1,19 +1,2 @@
|
|||||||
|
|
||||||
<div class="controls">
|
|
||||||
<button onclick="clearCanvas()">Clear</button>
|
|
||||||
</div>
|
|
||||||
<canvas id="cadCanvas" width="800" height="600"></canvas>
|
|
||||||
<div class="log">
|
|
||||||
<strong>Captured Lines:</strong>
|
|
||||||
<ul id="line-log"></ul>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="controls">
|
|
||||||
<button onclick="clearCanvas()">Clear</button>
|
|
||||||
</div>
|
|
||||||
<canvas id="cadCanvas" width="800" height="600"></canvas>
|
|
||||||
<div class="log">
|
|
||||||
<strong>Captured Lines:</strong>
|
|
||||||
<ul id="line-log"></ul>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,22 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
import Layout from "#layouts/Layout.astro";
|
import Layout from "#layouts/cadLayout.astro";
|
||||||
import CAD from "#components/CAD.svelte";
|
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
<Layout title="CAD">
|
||||||
|
|
||||||
|
<h1 class="text-3xl">CAD</h1>
|
||||||
|
|
||||||
|
<div class="controls">
|
||||||
|
<button onclick="clearCanvas()">Clear</button>
|
||||||
|
</div>
|
||||||
|
<canvas id="cadCanvas" width="800" height="600"></canvas>
|
||||||
|
<div class="log">
|
||||||
|
<strong>Captured Lines:</strong>
|
||||||
|
<ul id="line-log"></ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const canvas = document.getElementById('cadCanvas');
|
const canvas = document.getElementById('cadCanvas');
|
||||||
@@ -39,6 +54,26 @@ import CAD from "#components/CAD.svelte";
|
|||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear the canvas and reset logs
|
||||||
|
function clearCanvas() {
|
||||||
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
capturedLines = [];
|
||||||
|
startX = null;
|
||||||
|
startY = null;
|
||||||
|
drawGrid(); // Redraw the grid after clearing
|
||||||
|
updateLineLog();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the captured lines log
|
||||||
|
function updateLineLog() {
|
||||||
|
lineLog.innerHTML = capturedLines
|
||||||
|
.map((line, index) => {
|
||||||
|
const lengthInMeters = calculateLineLengthInMeters(line.startX, line.startY, line.endX, line.endY);
|
||||||
|
return <li>Line ${index + 1}: Start (${line.startX}, ${line.startY}), End (${line.endX}, ${line.endY}), Length: ${lengthInMeters.toFixed(2)} m</li>;
|
||||||
|
})
|
||||||
|
.join('');
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate the length of a line in meters
|
// Calculate the length of a line in meters
|
||||||
function calculateLineLengthInMeters(x1, y1, x2, y2) {
|
function calculateLineLengthInMeters(x1, y1, x2, y2) {
|
||||||
const dx = x2 - x1;
|
const dx = x2 - x1;
|
||||||
@@ -80,19 +115,5 @@ import CAD from "#components/CAD.svelte";
|
|||||||
drawGrid(); // Draw the grid when the page loads
|
drawGrid(); // Draw the grid when the page loads
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
|
|
||||||
<Layout title="CAD">
|
|
||||||
|
|
||||||
<h1 class="text-3xl">CAD</h1>
|
|
||||||
|
|
||||||
<div class="mt-12 m-auto w-[95%] relative">
|
|
||||||
<CAD client:load />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user