convert it and optimize to pure 2D. the purpose of this code is to make a schematics…
- User
convert it and optimize to pure 2D. the purpose of this code is to make a schematics drawer with snapable and adjustable grid. you can remove “Z” coordinate and optimize entire code accordingly to make it pure 2D representation. you can rename title to “schematoid” if you want. I would also added a unit conversion method here, to convert all dimension to some particular specific unit, as: em, cm, m, px and rest. <–not sure if this is need right now. if you have any interesting ideas you can integrate or tell me about them. <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne? <–answer to this maybe, ne?:
canvas.width = window.innerWidth; canvas.height = window.innerHeight;
let grid = []; let gridSize = 50; let gridSpacing = 25;
function updateGrid() { grid = []; for (let x = -gridSize; x <= gridSize; x += gridSpacing) { for (let y = -gridSize; y <= gridSize; y += gridSpacing) { grid.push({ x, y }); } } }
function updateCanvasSize() { canvas.width = window.innerWidth; canvas.height = window.innerHeight; }
function updateUI() { const gridSizeInput = document.getElementById(‘gridSize’); const gridSpacingInput = document.getElementById(‘gridSpacing’);
gridSizeInput.value = gridSize; gridSpacingInput.value = gridSpacing; }
function drawLine(line) { ctx.beginPath(); for (let i = 0; i < line.length - 1; i++) { const projectedStart = project(rotate(line[i])); const projectedEnd = project(rotate(line[i + 1]));
ctx.moveTo(projectedStart.x, projectedStart.y); ctx.lineTo(projectedEnd.x, projectedEnd.y); }
ctx.strokeStyle = ‘rgba(25,200,25,0.2)’; ctx.lineWidth = 2; ctx.stroke(); }
function calculateGridCenter(grid) { let totalX = 0; let totalY = 0; const pointsCount = grid.length;
for (const point of grid) { totalX += point.x; totalY += point.y; }
return { x: totalX / pointsCount, y: totalY / pointsCount }; }
const clickedPoints = []; let lastClickedPoint = null; let activeLine = null; const lines = [];
- Assistant