63 lines
No EOL
1.8 KiB
OpenSCAD
63 lines
No EOL
1.8 KiB
OpenSCAD
|
|
module key_dial(alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ", key="C", width=7, dia=50, thick=5.5, key_width=4, key_height=3, text_depth=1, font_size=-1, antipick=1.5, tolerance = 0.2, $fn = 60) {
|
|
key_indices = search(key, alphabet, 0);
|
|
assert(len(key_indices[0]) == 1, "key character not unique");
|
|
key_index = key_indices[0][0];
|
|
_font_size = font_size > 0 ? font_size : min(dia*PI/len(alphabet)/1.6, dia/10);
|
|
rotate([-0.5/len(alphabet)*360,0,0]) {
|
|
difference() {
|
|
rotate([0,90,0]) {
|
|
cylinder($fn=$fn, h=width, d=dia, center=true);
|
|
}
|
|
// inner ring
|
|
rotate([0,90,0]) {
|
|
cylinder($fn=$fn, h=width+2, d=dia-thick*2+2*tolerance, center=true);
|
|
}
|
|
// key
|
|
rotate([45+((0.5+key_index)/len(alphabet)) * 360,0,0]) {
|
|
translate([0,0,dia/2-thick]) {
|
|
cube([width+2, key_width, key_height*2], center=true);
|
|
}
|
|
}
|
|
// anti-picking keys
|
|
for (i = [1:len(alphabet)]) {
|
|
rotate([45+((i+0.5)/len(alphabet)) * 360,0,0]) {
|
|
translate([width/2,0,dia/2-thick]) {
|
|
cube([2*antipick, key_width, key_height*2], center=true);
|
|
}
|
|
}
|
|
}
|
|
// text
|
|
for (i = [0:len(alphabet)]) {
|
|
rotate([((i+0.5)/len(alphabet)) * 360,0,0]) {
|
|
translate([-width/2-1,-dia/2,dia/2-0.3]) {
|
|
cube([width+2,dia,5]);
|
|
}
|
|
translate([0,0,dia/2-text_depth-0.3]) {
|
|
linear_extrude(height=text_depth+1, convexity=3) {
|
|
text(alphabet[i], size=_font_size, halign="center", valign="center");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// DEFAULTS FOR COMMAND LINE INVOCATION
|
|
|
|
ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
KEY = "C";
|
|
DIAMETER = 50;
|
|
TOLERANCE = 0.2;
|
|
FN = 120;
|
|
INDEX = 0;
|
|
|
|
rotate([0,-90,0]) {
|
|
key_dial(
|
|
alphabet=ALPHABET,
|
|
key=KEY,
|
|
dia=DIAMETER,
|
|
tolerance=TOLERANCE, $fn=FN);
|
|
} |