From 1533d78a41c592a691d5a0401ca50c079ca611b0 Mon Sep 17 00:00:00 2001 From: Karel Vervaeke Date: Sat, 3 Aug 2013 10:15:16 +0200 Subject: [PATCH 1/2] Modularized name_tag --- bitmap/name_tag.scad | 55 ++++++++++++++++++--------------------- bitmap/test_name_tag.scad | 19 ++++++++++++++ 2 files changed, 45 insertions(+), 29 deletions(-) create mode 100644 bitmap/test_name_tag.scad diff --git a/bitmap/name_tag.scad b/bitmap/name_tag.scad index 7687c54..366dce0 100644 --- a/bitmap/name_tag.scad +++ b/bitmap/name_tag.scad @@ -7,33 +7,30 @@ http://creativecommons.org/licenses/by/3.0/ use -// change chars array and char_count -// OpenSCAD has no string or length methods :( -chars = ["R", "E", "P", "R", "A", "P"]; -char_count = 6; - - -// block size 1 will result in 8mm per letter -block_size = 2; -// height is the Z height of each letter -height = 3; -// Append a hole fo a keyring, necklace etc. ? -key_ring_hole = true; - -union() { - translate(v = [0,-block_size*8*char_count/2+block_size*8/2,3]) { - 8bit_str(chars, char_count, block_size, height); - } - translate(v = [0,0,3/2]) { - color([0,0,1,1]) { - cube(size = [block_size * 8, block_size * 8 * char_count, 3], center = true); - } - } - if (key_ring_hole == true){ - translate([0, block_size * 8 * (char_count+1)/2, 3/2]) - difference(){ - cube(size = [block_size * 8, block_size * 8 , 3], center = true); - cube(size = [block_size * 4, block_size * 4 , 5], center = true); - } - } +/* + chars = chars array + char_count = number of characters (OpenSCAD has no string or length methods) + block_size = letter size (block size 1 will result in 8mm per letter) + height = the Z height of each letter in mm + key_ring_hole = (boolean) Append a hole to a keyring, necklace etc. ? +*/ +module name_tag(chars = ["R", "E", "P", "R", "A", "P"], char_count = 6, + block_size = 2, height = 3, key_ring_hole = true) { + union() { + translate(v = [0,-block_size*8*char_count/2+block_size*8/2,3]) { + 8bit_str(chars, char_count, block_size, height); + } + translate(v = [0,0,3/2]) { + color([0,0,1,1]) { + cube(size = [block_size * 8, block_size * 8 * char_count, 3], center = true); + } + } + if (key_ring_hole == true){ + translate([0, block_size * 8 * (char_count+1)/2, 3/2]) + difference(){ + cube(size = [block_size * 8, block_size * 8 , 3], center = true); + cube(size = [block_size * 4, block_size * 4 , 5], center = true); + } + } + } } diff --git a/bitmap/test_name_tag.scad b/bitmap/test_name_tag.scad new file mode 100644 index 0000000..a921491 --- /dev/null +++ b/bitmap/test_name_tag.scad @@ -0,0 +1,19 @@ +include <../bitmap/name_tag.scad>; + +translate([0,0,0]) +name_tag(["n","a","m","e","_","t","a","g"], 8); + +translate([20,0,0]) // 0 + 16/2 + 16/2 + 4 +name_tag(["N","A","M","E","_","T","A","G"], 8); + +translate([52,0,0]) // 20 + 16/2 + 40/2 + 4 +name_tag(chars=["n","a","m","e","_","t","a","g"], char_count=8, block_size=5); + +translate([96,0,0]) // 52 + 40/2 + 40/2 + 4 +name_tag(chars=["N","A","M","E","_","T","A","G"], char_count=8, block_size=5); + +translate([130,0,0]) // 92 + 40/2 + 16/2 + 4 +name_tag(["n","a","m","e","_","t","a","g"], char_count=8, height=30); + +translate([150,0,0]) // 130 + 16/2 + 16/2 + 4 +name_tag(["N","A","M","E","_","T","A","G"], char_count=8, height=30); From da49a8e27a5eefaf9f8871c827134714f5a098c9 Mon Sep 17 00:00:00 2001 From: Karel Vervaeke Date: Sun, 4 Aug 2013 20:26:30 +0200 Subject: [PATCH 2/2] char_count can be determined using len(), so no need to pass it as an argument --- bitmap/name_tag.scad | 4 ++-- bitmap/test_name_tag.scad | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bitmap/name_tag.scad b/bitmap/name_tag.scad index 366dce0..4b392bb 100644 --- a/bitmap/name_tag.scad +++ b/bitmap/name_tag.scad @@ -9,13 +9,13 @@ use /* chars = chars array - char_count = number of characters (OpenSCAD has no string or length methods) block_size = letter size (block size 1 will result in 8mm per letter) height = the Z height of each letter in mm key_ring_hole = (boolean) Append a hole to a keyring, necklace etc. ? */ -module name_tag(chars = ["R", "E", "P", "R", "A", "P"], char_count = 6, +module name_tag(chars = ["R", "E", "P", "R", "A", "P"], block_size = 2, height = 3, key_ring_hole = true) { + char_count = len(chars); union() { translate(v = [0,-block_size*8*char_count/2+block_size*8/2,3]) { 8bit_str(chars, char_count, block_size, height); diff --git a/bitmap/test_name_tag.scad b/bitmap/test_name_tag.scad index a921491..a3bcf40 100644 --- a/bitmap/test_name_tag.scad +++ b/bitmap/test_name_tag.scad @@ -1,19 +1,19 @@ include <../bitmap/name_tag.scad>; translate([0,0,0]) -name_tag(["n","a","m","e","_","t","a","g"], 8); +name_tag("name_tag"); translate([20,0,0]) // 0 + 16/2 + 16/2 + 4 -name_tag(["N","A","M","E","_","T","A","G"], 8); +name_tag("NAME_TAG"); translate([52,0,0]) // 20 + 16/2 + 40/2 + 4 -name_tag(chars=["n","a","m","e","_","t","a","g"], char_count=8, block_size=5); +name_tag("name_tag", block_size=5); translate([96,0,0]) // 52 + 40/2 + 40/2 + 4 -name_tag(chars=["N","A","M","E","_","T","A","G"], char_count=8, block_size=5); +name_tag("NAME_TAG", block_size=5); translate([130,0,0]) // 92 + 40/2 + 16/2 + 4 -name_tag(["n","a","m","e","_","t","a","g"], char_count=8, height=30); +name_tag("name_tag", height=30); translate([150,0,0]) // 130 + 16/2 + 16/2 + 4 -name_tag(["N","A","M","E","_","T","A","G"], char_count=8, height=30); +name_tag("NAME_TAG", height=30);