Created
June 22, 2019 14:00
-
-
Save ednisley/a227da0bb06e62f9d22e07e4c408429e to your computer and use it in GitHub Desktop.
GCMC and Bash source code: Demonstration of wrapping text around an arc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Map text to circular arcs | |
// Ed Nisley KE4ZNU - 2019-06 | |
//----- | |
// Command line parameters | |
// -D OuterDia=number | |
if (!isdefined("OuterDia")) { | |
OuterDia = 120mm - 2mm; // CD = 120, 3.5 inch drive = 95 | |
} | |
OuterRad = OuterDia / 2.0; | |
comment("Outer Diameter: ",OuterDia); | |
comment(" Radius: ",OuterRad); | |
//----- | |
// Library routines | |
include("tracepath.inc.gcmc"); | |
include("engrave.inc.gcmc"); | |
//----- | |
// Bend text around an arc | |
function ArcText(TextPath,Center,Radius,BaseAngle,Align) { | |
PathLength = TextPath[-1].x - TextPath[1].x; | |
Circumf = 2*pi()*Radius; | |
TextAngle = to_deg(360 * PathLength / Circumf); | |
AlignAngle = BaseAngle + (Align == "Left" ? 0 : | |
Align == "Center" ? -TextAngle / 2 : | |
Align == "Right" ? -TextAngle : | |
0); | |
ArcPath = {}; | |
foreach(TextPath; pt) { | |
if (!isundef(pt.x) && !isundef(pt.y) && isundef(pt.z)) { // XY motion, no Z | |
r = Radius - pt.y; | |
a = 360deg * (pt.x / Circumf) + AlignAngle; | |
ArcPath += {[r*cos(a) + Center.x, r*sin(a) + Center.y,-]}; | |
} | |
elif (isundef(pt.x) && isundef(pt.y) && !isundef(pt.z)) { // no XY, Z up/down | |
ArcPath += {pt}; | |
} | |
else { | |
error("Point is not pure XY or pure Z: " + to_string(pt)); | |
} | |
} | |
return ArcPath; | |
} | |
//----- | |
// Set up for drawing | |
TravelZ = 1.0mm; // no clamps above workpiece! | |
PlotZ = -1.0mm; // tune for best results | |
TextSpeed = 100mm; // minimal shaking | |
DrawSpeed = 500mm; // smooth curve drawing | |
TextFont = FONT_HSANS_1_RS; | |
TextSize = [2.0mm,2.0mm]; | |
TextLeading = 5.0mm; // line spacing | |
DiskCenter = [0mm,0mm]; // middle of the platter | |
if (1) { | |
comment("Circles begin"); | |
TextRadius = OuterRad; | |
for (r = OuterRad; r >= 25mm; r -= TextLeading) { | |
feedrate(DrawSpeed); | |
goto([-,-,TravelZ]); | |
goto([r,0,-]); | |
move([-,-,PlotZ]); | |
circle_cw([0,0]); | |
goto([-,-,TravelZ]); | |
tp = scale(typeset("Radius: " + to_string(r),TextFont),TextSize); | |
tpa = ArcText(tp,DiskCenter,r,115deg,"Left"); | |
feedrate(TextSpeed); | |
engrave(tpa,TravelZ,PlotZ); | |
} | |
} | |
if (1) { | |
comment("Depth variations begin"); | |
TextRadius = OuterRad; | |
feedrate(TextSpeed); | |
for (pz = 0.0mm; pz >= -0.6mm; pz -= 0.10mm) { | |
comment(" depth: " + to_string(pz)); | |
ts = "Depth: " + to_string(pz) + " at " + to_string(TextSpeed) + "/s"; | |
tp = scale(typeset(ts,TextFont),TextSize); | |
tpa = ArcText(tp,DiskCenter,TextRadius,-5deg,"Right"); | |
engrave(tpa,TravelZ,pz); | |
TextRadius -= TextLeading; | |
} | |
} | |
if (1) { | |
comment("Feedrate variations begin"); | |
TextRadius = OuterRad; | |
for (ps = 50mm; ps <= 350mm; ps += 50mm) { | |
feedrate(ps); | |
comment(" speed: " + to_string(ps) + "/s"); | |
ts = "Speed: " + to_string(ps) + "/s at " + to_string(PlotZ); | |
tp = scale(typeset(ts,TextFont),TextSize); | |
tpa = ArcText(tp,DiskCenter,TextRadius,5deg,"Left"); | |
engrave(tpa,TravelZ,PlotZ); | |
TextRadius -= TextLeading; | |
} | |
} | |
if (1) { | |
comment("Off-center text arcs begin"); | |
feedrate(TextSpeed); | |
tc = [-40mm/sqrt(2),-40mm/sqrt(2)]; // center point | |
r = 8mm; | |
s = [1.5mm,1.5mm]; | |
ts = "Radius: " + to_string(r) + " Size: " + to_string(s); | |
tp = scale(typeset(ts,TextFont),s); | |
tpa = ArcText(tp,tc,r,0deg,"Center"); | |
engrave(tpa,TravelZ,PlotZ); | |
r = 5mm; | |
s = [1.0mm,1.0mm]; | |
ts = "Radius: " + to_string(r) + " Size: " + to_string(s); | |
tp = scale(typeset(ts,TextFont),s); | |
tpa = ArcText(tp,tc,r,0deg,"Center"); | |
engrave(tpa,TravelZ,PlotZ); | |
r = 15mm; | |
s = [3.0mm,3.0mm]; | |
ts = "Radius: " + to_string(r) + " Size: " + to_string(s); | |
tp = scale(typeset(ts,TextFont),s); | |
tpa = ArcText(tp,tc,r,0deg,"Center"); | |
engrave(tpa,TravelZ,PlotZ); | |
} | |
if (1) { | |
comment("Attribution begins"); | |
tp = scale(typeset("Ed Nisley - KE4ZNU - softsolder.com",TextFont),TextSize); | |
tpa = ArcText(tp,DiskCenter,15mm,0deg,"Center"); | |
feedrate(TextSpeed); | |
engrave(tpa,TravelZ,PlotZ); | |
} | |
goto([-,-,10mm]); | |
goto([0mm,0mm,-]); | |
comment("Done!"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Arc Lettering Generator | |
# Ed Nisley KE4ZNU - 2019-06 | |
Diameter='OuterDia=116mm' | |
Flags='-P 3 --pedantic' | |
# Set these to match your file layout | |
LibPath='/opt/gcmc/library' | |
Prolog='/mnt/bulkdata/Project Files/Mostly Printed CNC/Firmware/gcmc/prolog.gcmc' | |
Epilog='/mnt/bulkdata/Project Files/Mostly Printed CNC/Firmware/gcmc/epilog.gcmc' | |
Script='/mnt/bulkdata/Project Files/Mostly Printed CNC/Patterns/Arc Lettering/ArcLetter.gcmc' | |
ts=$(date +%Y%m%d-%H%M%S) | |
fn='ArcLetter_'${ts}'.ngc' | |
echo Output: $fn | |
rm -f $fn | |
echo "(File: "$fn")" > $fn | |
gcmc -D $Diameter $Flags \ | |
--include "$LibPath" --prologue "$Prolog" --epilogue "$Epilog" \ | |
"$Script" >> $fn | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More details on my blog at https://wp.me/poZKh-8g9