Text and circle


Characters container generator is one of my hot things on Thingiverse.

Characters container generator

Wrapping text around a circle

Making a thing like this is easy. You just wrap text around a circle, draw a circle ring, linear_extrude them and add a bottom. We've seen how to draw a circle in Circle. One way to do that is using lines. If you replace lines by characters, you can reuse the code template.

radius = 50;
chars = "IT WORKS ON MY MACHINE ";

module revolve_text(radius, chars) {
    PI = 3.14159;
    circumference = 2 * PI * radius;
    chars_len = len(chars);
    font_size = circumference / chars_len;
    step_angle = 360 / chars_len;
    for(i = [0 : chars_len - 1]) {
        rotate(-i * step_angle) 
            translate([0, radius + font_size / 2, 0]) 
                text(
                    chars[i], 
                    font = "Courier New; Style = Bold", 
                    size = font_size, 
                    valign = "center", halign = "center"
                );
    }
}

revolve_text(radius, chars);

Text and circle

The above code is one of the implementations. If you fix the radius, you fix the circumference, and the number of the characters determines the size of each character. Remember? A circle can be composed of many short lines. Even though the character itself is a plane, wrapping more characters will make the model more like a circle.

Characters container generator is an example taking this implementation. You can input your sentence in it. If you fix the radius and input more characters, each character will be smaller. To prevent characters from being too small to print, you may increase the radius if you want to input many characters.

In my another work Character tower generator, I fix the number of characters of a circle. I'll talk about it in a later document. Depending on the effect you want, a constant character size is also a way you may take.

The circle

Once you've made a text ring, it's admittedly easy to add a circle ring in it, right? After all, you just have to draw a circle and different a smaller circle from it. What will you ring be? Such as this?

Text and circle

My Characters container generator draws like this. I created it at my early time on OpenSCAD, so I didn't consider some possible facets of this. Look the above figure carefully. The character and the line are not mutually perpendicular. I intentionally make $fn == 12 to highlight this situation.

What problem will it cause? Irregular intersections will increase the complexity of the model, take more time to render, consume more memories, and grow the size of the exported file, such as STL. Sometimes, it's even possible to get unexpected warnings or errors.

What I want here is, the number of characters determines the value of $fn and the character and the line are mutually perpendicular. It prevents the above problems, and the model will look neater.

You may observe how the circle module draws a circle. The starting point of the first line is always [x, 0], but the above revolve_text module draws its first character at [0, y]. We can rotate the circle 90 degrees first, and then rotate it 360 / $fn / 2 again. After that, the character and the line are mutually perpendicular.

revolve_text(radius, chars);
rotate(90 + 180 / len(chars)) 
    circle(radius, $fn = len(chars));

Text and circle

Now, I think it's easy to complete Characters container generator. It is an exercise for you.