Skip to content

Instantly share code, notes, and snippets.

@mutterer
Created January 22, 2023 21:39
Show Gist options
  • Save mutterer/aa36efe2d8e353581c5b64466d8974ad to your computer and use it in GitHub Desktop.
Save mutterer/aa36efe2d8e353581c5b64466d8974ad to your computer and use it in GitHub Desktop.
draws a line, and overlays its profile and some infos
// This tool draws a line, and overlays its profile and some infos
// 2023-01-22 fixed profile origin by moving Overlay.moveTo after setColor.
macro "Line and Profile Tool -C00bL1de0L1ee1" {
getCursorLoc(x, y, z, flags);
xstart = x; ystart = y;
x2=x; y2=y;
while (true) {
getCursorLoc(x, y, z, flags);
if (flags&16==0) {
dx=x2-xstart; dy=y2-ystart;
exit;
}
if (x!=x2 || y!=y2) {
makeLine(xstart, ystart, x, y);
overlayProfile(xstart, ystart, x, y);
}
x2=x; y2=y;
wait(10);
};
}
}
 
function overlayProfile(xa,ya,xb,yb) {
Overlay.remove;
p = getProfile();
Array.getStatistics(p, min, max, mean, stdDev);
List.setMeasurements;
text = 'Length:'+d2s(List.getValue('Length'),2)+'\nmin:'+d2s(min,2)+'\nmax:'+d2s(max,2);
setFont('SanSerif', 14, 'bold antialiased');
setColor('black');
Overlay.drawString(text, 10-1, 20-1);
setColor('cyan');
Overlay.drawString(text, 10, 20);
setColor('green');
setLineWidth(2);
Overlay.moveTo(xa, ya);
for (i=0;i<p.length;i++) {
xs = (xb-xa)/p.length;
ys = (ya-yb)/p.length;
d = 100-100*p[i]/max;
a = atan ((yb-ya)/(xb-xa));
Overlay.lineTo(xa+i*xs-d*sin(a), ya-i*ys+d*cos(a));
}
Overlay.lineTo(xb, yb);
Overlay.show;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment