forked from KitWallace/openscad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbraille.scad
96 lines (72 loc) · 4.2 KB
/
braille.scad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
based on http://www.thingiverse.com/thing:8000
mods :
braille font parameters set as global variables (prefixed $) for clarity
resolution set globally
module for printing the label, multiple lines -drawText() - as well as a line - drawLine()
dropped the difference operation when drawing dots since embedded in slab anyway
dot sphere offset because spec requires base which is longer than 2 times the height
functions added to compute the radius from a chord length and height
length() > len()
max line length calculated with recursive function so width of slab
can be calculated
todo mark so the fitter knows which way up it goes - chamfer top edge?
allow capitials -openSCAD lacks a function to change the case of a letter,
hence the duplicate entries for both forms of the letter
adding the shift character for an uppercase letter is tricky since cannot simply
accumulate the length printed
use search instead of looping throught the parallel array for easier maintenance
*/
function max_length_r(v, i, max) =
i == len(v) ? max : max_length_r(v, i+1, len(v[i]) > max ? len(v[i]) : max);
function max_length(v) = max_length_r(v,0,0);
// dot is not a hemisphere
function chord_radius(length,height) = ( length * length /(4 * height) + height)/2;
$charKeys = ["a", "A", "b", "B", "c", "C", "d", "D", "e", "E", "f", "F", "g", "G", "h", "H", "i", "I", "j", "J", "k", "K", "l", "L", "m", "M", "n", "N", "o", "O", "p", "P", "q", "Q", "r", "R", "s", "S", "t", "T", "u", "U", "v", "V", "w", "W", "x", "X", "y", "Y", "z", "Z", ",", ";", ":", ".", "!", "(", ")", "?", "\"", "*", "'", "-"];
$charValues = [[1], [1], [1, 2], [1, 2], [1, 4], [1, 4], [1, 4, 5], [1, 4, 5], [1, 5], [1, 5], [1, 2, 4], [1, 2, 4], [1, 2, 4, 5], [1, 2, 4, 5], [1, 2, 5], [1, 2, 5], [2, 4], [2, 4], [2, 4, 5], [2, 4, 5], [1, 3], [1, 3], [1, 2, 3], [1, 2, 3], [1, 3, 4], [1, 3, 4], [1, 3, 4, 5], [1, 3, 4, 5], [1, 3, 5], [1, 3, 5], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 5], [1, 2, 3, 5], [2, 3, 4], [2, 3, 4], [2, 3, 4, 5], [2, 3, 4, 5], [1, 3, 6], [1, 3, 6], [1, 2, 3, 6], [1, 2, 3, 6], [2, 4, 5, 6], [2, 4, 5, 6], [1, 3, 4, 6], [1, 3, 4, 6], [1, 3, 4, 5, 6], [1, 3, 4, 5, 6], [1, 3, 5, 6], [1, 3, 5, 6], [2], [2, 3], [2, 5], [2, 5, 6], [2, 3, 5], [2, 3, 5, 6], [2, 3, 5, 6], [2, 3, 6], [2, 3, 6], [3, 5], [3], [3, 6]];
module drawDot(location) {
translate(location)
translate ([0,0, -$dotSphereOffset ]) sphere($dotSphereRadius);
}
module drawCharacter(charMap) {
for(i = [0: len(charMap)-1])
assign(dot = charMap[i] - 1)
drawDot( [floor(dot / 3) * $dotWidth, -((dot %3) * $dotWidth), 0], $dotRadius );
}
module drawLine(line) {
for(i = [0: len(line)-1])
translate([$charWidth*i, 0, 0])
for(j = [0:len($charKeys)])
if($charKeys[j] == line[i])
drawCharacter($charValues[j]);
}
module drawText(text) {
assign(totalHeight = len(text) * $lineHeight)
translate([0, 0, 1])
for(i = [0: len(text)])
translate([-len(text[i])*$charWidth/2, totalHeight/2-$lineHeight*i, 0])
drawLine(text[i]);
}
module label(text, depth=2) {
assign(width =( max_length(text) + 2) * $charWidth,
height = len(text) * $lineHeight)
union() {
translate([0, $lineHeight/3, 0])
cube([width,height, depth], true);
drawText(text);
}
}
$fa = 0.01; $fs = 0.5;
// global dimensions from http://www.brailleauthority.org/sizespacingofbraille/sizespacingofbraille.pdf
$dotHeight = 0.48;
$dotBase = 1.44;
$dotRadius = $dotBase /2;
$dotWidth= 2.34;
$charWidth = 6.2;
$lineHeight = 10;
// compute the sphere to make the raised dot
$dotSphereRadius = chord_radius($dotBase,$dotHeight);
$dotSphereOffset =$dotSphereRadius - $dotHeight;
text = ["Hello"];
// text = ["All human beings are born", "free and equal in dignity and", "rights. They are endowed with", "reason and conscience and", "should act towards one another", "in a spirit of brotherhood."];
label(text);