Last active
November 27, 2019 12:02
-
-
Save ednisley/1fa44b93c5bc994dc9d86f41af9edf29 to your computer and use it in GitHub Desktop.
GCMC source code: draw text along radial line
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
comment("RadialText test"); | |
ctr = [0mm,0mm]; | |
r = 20mm; | |
a = 0deg; | |
tp = scale(typeset("Left Inward",TextFont),LegendTextSize); | |
tpr = RadialText(tp,ctr,r,a,TEXT_LEFT,INWARD); | |
feedrate(TextSpeed); | |
engrave(tpr,TravelZ,EngraveZ); | |
tp = scale(typeset("Left Outward",TextFont),LegendTextSize); | |
tpr = RadialText(tp,ctr,r,a,TEXT_LEFT,OUTWARD); | |
feedrate(TextSpeed); | |
engrave(tpr,TravelZ,EngraveZ); | |
a = 90deg; | |
tp = scale(typeset("Right Inward",TextFont),LegendTextSize); | |
tpr = RadialText(tp,ctr,r,a,TEXT_RIGHT,INWARD); | |
feedrate(TextSpeed); | |
engrave(tpr,TravelZ,EngraveZ); | |
tp = scale(typeset("Right Outward",TextFont),LegendTextSize); | |
tpr = RadialText(tp,ctr,r,a,TEXT_RIGHT,OUTWARD); | |
feedrate(TextSpeed); | |
engrave(tpr,TravelZ,EngraveZ); | |
a = 180deg; | |
tp = scale(typeset("Center Inward",TextFont),LegendTextSize); | |
tpr = RadialText(tp,ctr,r,a,TEXT_CENTERED,INWARD); | |
feedrate(TextSpeed); | |
engrave(tpr,TravelZ,EngraveZ); | |
tp = scale(typeset("Center Outward",TextFont),LegendTextSize); | |
tpr = RadialText(tp,ctr,r,a,TEXT_CENTERED,OUTWARD); | |
feedrate(TextSpeed); | |
engrave(tpr,TravelZ,EngraveZ); | |
a = 270deg; | |
RadialLegend("Offset to radius",ctr,r,a,TEXT_CENTERED,INWARD,-0.5); | |
goto(ctr); | |
move([0,-2*r,EngraveZ]); | |
goto([r,0mm,-]); | |
circle_cw(ctr); |
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
//----- | |
// Write text on a radial line | |
function RadialText(TextPath,CenterPt,Radius,Angle,Justify,Orient) { | |
local pl = TextPath[-1].x; // path length | |
local ji = (Justify == TEXT_LEFT) ? 0mm : // justification indent | |
(Justify == TEXT_CENTERED) ? -pl/2 : | |
(Justify == TEXT_RIGHT) ? -pl : | |
0mm; | |
if (Orient == INWARD) { | |
TextPath = rotate_xy(TextPath,180deg); | |
ji = -ji; | |
} | |
TextPath += [Radius + ji,0mm]; | |
return rotate_xy(TextPath,Angle) + CenterPt; | |
} | |
//----- | |
// Draw a radial legend | |
// Offset in units of char height: 0 = baseline on radius, +/- = above/below | |
function RadialLegend(Text,Center,Radius,Angle,Justify,Orient,Offset) { | |
local tp = scale(typeset(Text,TextFont),LegendTextSize) + [0mm,Offset * LegendTextSize.y]; | |
local tpr = RadialText(tp,Center,Radius,Angle,Justify,Orient); | |
feedrate(TextSpeed); | |
engrave(tpr,TravelZ,EngraveZ); | |
} | |
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-8B2