Text
Text
Beginner
Making a Name Tag
Section titled “Making a Name Tag”
// use linear_extrude() to make 3D$fa = 1;$fs = 0.4;
s = "TODOPROGRAMMING";size = 20;font = "Liberation Serif";padding = 7;
function is_upper(c) = ord(c) >= 65 && ord(c) <= 90;function is_lower(c) = ord(c) >= 97 && ord(c) <= 122;function is_digit(c) = ord(c) >= 48 && ord(c) <= 57;
// Text metrics are a thing but not in the stable buildfunction char_width_factor(c) = c == " " ? 0.33 : is_upper(c) ? 0.94 : is_lower(c) ? 0.56 : is_digit(c) ? 0.58 : 0.45;
function width_factor_sum(i = 0, acc = 0) = i >= len(s) ? acc : width_factor_sum(i + 1, acc + char_width_factor(s[i]));
text_width = size * width_factor_sum(); text_height = size * 1.15;
translate([0, 0, 1]) linear_extrude(4) text(s, size=size, font=font, halign="center", valign="center");
translate([0, 0, 0]) color("black") cube([text_width + padding * 2, text_height + padding, 3], center=true);