Public
Edited
Nov 20, 2023
2 forks
7 stars
Insert cell
Insert cell
Insert cell
Insert cell
plotW = 404
Insert cell
plotH = 276
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
plotterSteps = 0.025 // 0.025mm steps
Insert cell
Insert cell
sortedPaths = {
let sortedPaths = []
let ppaths = paths.map(s => s.map(p => p.clone()))
let pos = PVector(0, 0)
while(ppaths.length) {
const p = ppaths.sort((a, b) => Math.min(pos.distSq(a[0]), pos.distSq(a[1])) - Math.min(pos.distSq(b[0]), pos.distSq(b[1])))
let closest = p.shift()
if(pos.distSq(closest[0]) > pos.distSq(closest[1])) closest = closest.reverse()
pos = closest[1].copy()
sortedPaths.push(closest)
}

return sortedPaths
}
Insert cell
landscapeToPortrait = ({x, y}, width, height) => ({x: width - y, y: x})
Insert cell
rotatedPaths = paths.map(p => p.map(pt => PVector(landscapeToPortrait(pt, plotW, plotH))))
Insert cell
svg`<svg height="${svgDisplayHeight}" viewBox="0 0 ${plotW} ${plotH}">
<g transform="translate(0,${plotH}) scale(1, -1)">
${rotatedPaths.map((p,i) => `<line x1="${p[0].x}" y1="${p[0].y}" x2="${p[1].x}" y2="${p[1].y}" stroke-width=".25" stroke="black"/>`)}
${rotatedPaths.map((p,i) => `${i === 0 ? '' : `<line x1="${rotatedPaths[i-1][1].x}" y1="${rotatedPaths[i-1][1].y}" x2="${p[0].x}" y2="${p[0].y}" stroke-width=".1" stroke="red"/>`}`)}
</g>
</svg>`
Insert cell
cmd = {
let cmd = 'SP1;PU0,0;'
cmd += rotatedPaths.map((p, i) => {
p = p.map(v => v.clone().div(plotterSteps).round())
return `PU${p[0].x},${p[0].y};PD${p[1].x},${p[1].y};`
}).join('')
cmd += `SP;PU${plotW/plotterSteps|0},${plotH/plotterSteps|0};`
return cmd
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more