diff --git a/README b/README index 1f99f4b8fce5ad65a55f5a4a55a087d02a886daf..d1d27ccd2d3361db84b11a2840bcf6cfde2e9c8a 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ This is an OpenSCAD module that let's you easily (well kinda) create 3D text. I've emulated the Atari 8-Bit fonts A-Z, a-z, 0-9, and most punctuation. You can create them a letter at a time or pass an array of characters. (OpenSCAD doesn't have any real string manipulation) -It also has a bitmap module that you can use to define your own fonts. It's pretty simple, you pass it an array of 1s and 0s, then tell it how many bits per row and it creates cubes (of configurable width and height) in a grid and combines them into a single shape. +It also has a bitmap module that you can use to define your own fonts. It's pretty simple, you pass it an array of numbers, then tell it how many bits per row and it creates cubes (of configurable width and height) in a grid and combines them into a single shape. The number in the array sets the pixel height modifier. So if you set height to 5 and the array value is 2, then the height of that pixel will be 10mm. Be careful when defining your own bitmaps in that you can't have two bits only connected diagonally. Otherwise OpenSCAD will say it's not manifold. For instance you can't have: diff --git a/bitmap.scad b/bitmap.scad index c68986b73d4d7622ad9fd547ce82eb88655a5d24..38a0d0dc2d54fd3a8f5b0a58e8f9584bc4106b30 100644 --- a/bitmap.scad +++ b/bitmap.scad @@ -11,13 +11,14 @@ module bitmap(bitmap, block_size, height, row_size) { function loc_x(loc) = floor(loc / row_size) * block_size; function loc_y(loc) = loc % row_size * block_size; + function loc_z(loc) = (bitmap[loc]*height-height)/2; translate(v = [-width/2+block_size/2,-width/2+block_size/2,height/2]) { for (loc = [0:bitmap_size - 1]) { - if (bitmap[loc] == 1) { + if (bitmap[loc] != 0) { union() { - translate(v = [loc_x(loc), loc_y(loc), 0]) { - cube(size = [block_size, block_size, height], center = true); + translate(v = [loc_x(loc), loc_y(loc), loc_z(loc)]) { + cube(size = [block_size, block_size, height * bitmap[loc]], center = true); } } } diff --git a/height_map.scad b/height_map.scad new file mode 100644 index 0000000000000000000000000000000000000000..6a5e4fa70d330696fa90f58ea1b8b970787ec7ba --- /dev/null +++ b/height_map.scad @@ -0,0 +1,31 @@ +/* +Height Map Example +Tony Buser +http://tonybuser.com +http://creativecommons.org/licenses/by/3.0/ + +Can also dynamically run this by passing an array on the command line: + +/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD -m make -D bitmap=[2,2,2,0,1,3,2,2,2] -D row_size=3 -s height_map.stl height_map.scad +*/ + + + +block_size = 5; +height = 5; + +row_size = 10; // 10x10 pixels +bitmap = [ + 1,1,0,0,1,1,0,0,1,1, + 1,1,1,1,1,1,1,1,1,1, + 0,1,2,2,1,1,2,2,1,0, + 0,1,2,1,1,1,1,2,1,0, + 1,1,1,1,3,3,1,1,1,1, + 1,1,1,1,3,3,1,1,1,1, + 0,1,2,1,1,1,1,2,1,0, + 0,1,2,2,1,1,2,2,1,0, + 1,1,1,1,1,1,1,1,1,1, + 1,1,0,0,1,1,0,0,1,1 +]; + +bitmap(bitmap, block_size, height, row_size);