I’m currently writing a script that’ll curve text around a circle whilst staying upright. I’ve used my good pal ChatGPT but can’t prompt out a solution for this.
I understand that you can’t accumulate angles which would make this simpler if I could but was wondering if anybody could point me in the direction of the resources that might solve the issue.
Here’s my current code:
`
function is_fat_char(c) = c == "W" || c == "w" || c == "m" || c == "M" || c == "B";
function is_thin_char(c) = c == "i" || c == "l" || c == "|" || c == ".";
module bend_text_along_circle(text, font_size, circle_diameter, letter_spacing) {
radius = circle_diameter / 2;
num_letters = len(text);
total_angle = (num_letters - 1) * letter_spacing;
start_angle = -total_angle / 2;
extra = 0;
previous_letter_extra = 0;
for (i = [0:num_letters-1]) {
letter = str(text[i]);
previous_letter = i > 0 ? str(text[i-1]) : "";
// This isn't right, but I think this is where I need to find out if it's fat or not.
extra = is_thin_char(letter) ? -0.3 : (is_fat_char(letter) ? 0.3 : 0;
angle = start_angle + (i * (letter_spacing + extra));
echo("Letter: ", letter, " Previous Letter: ", previous_letter,
" Extra spacing: ", letter_spacing,
" Previous Extra", previous_letter_extra,
"Angle:",angle);
// Position and rotate each letter
translate([radius * cos(angle), radius * sin(angle), 7])
rotate([0, 0, angle + 90])
linear_extrude(height = 1)
text(letter, size = font_size, valign = "baseline", halign = "center");
}
}
// Usage: text, font size, circle diameter, letter spacing (in degrees)
bend_text_along_circle("bailey works", 4.5, 32, 14);
`
I’ve tried a few things which have led me to understand that I either need to calculate all the letters positions before hand and read them back out. Or just live with my decision to end up down this rabbit hole!
The goal is –
- W’s & M’s have more space so they don’t overlap
- I, i, l, t have less space so they don’t feel so lost
I’m in OpenSCAD.
:This is what it looks like – that is incorrect
Barney Vaughan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1