From 94e528fddcf6886f034941619216a34f2c2c068f Mon Sep 17 00:00:00 2001 From: Tony Buser Date: Fri, 26 Mar 2010 01:42:27 -0400 Subject: [PATCH] added height map support --- README | 2 +- bitmap.scad | 7 ++++--- height_map.scad | 31 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 height_map.scad diff --git a/README b/README index 1f99f4b..d1d27cc 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 c68986b..38a0d0d 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 0000000..6a5e4fa --- /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);