added height map support
This commit is contained in:
parent
f77a2d96b9
commit
94e528fddc
2
README
2
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)
|
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:
|
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:
|
||||||
|
|
||||||
|
|
|
@ -11,13 +11,14 @@ module bitmap(bitmap, block_size, height, row_size) {
|
||||||
|
|
||||||
function loc_x(loc) = floor(loc / row_size) * block_size;
|
function loc_x(loc) = floor(loc / row_size) * block_size;
|
||||||
function loc_y(loc) = 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]) {
|
translate(v = [-width/2+block_size/2,-width/2+block_size/2,height/2]) {
|
||||||
for (loc = [0:bitmap_size - 1]) {
|
for (loc = [0:bitmap_size - 1]) {
|
||||||
if (bitmap[loc] == 1) {
|
if (bitmap[loc] != 0) {
|
||||||
union() {
|
union() {
|
||||||
translate(v = [loc_x(loc), loc_y(loc), 0]) {
|
translate(v = [loc_x(loc), loc_y(loc), loc_z(loc)]) {
|
||||||
cube(size = [block_size, block_size, height], center = true);
|
cube(size = [block_size, block_size, height * bitmap[loc]], center = true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
31
height_map.scad
Normal file
31
height_map.scad
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
Height Map Example
|
||||||
|
Tony Buser <tbuser@gmail.com>
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
|
||||||
|
<bitmap.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);
|
Loading…
Reference in a new issue