From cc8fa6bf231a3add40f94280b0b8d99041bfcd78 Mon Sep 17 00:00:00 2001 From: deboxed Date: Tue, 3 Feb 2026 13:19:51 +0100 Subject: [PATCH 1/3] add initial text stamp/stencil generator --- main.scad | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 main.scad diff --git a/main.scad b/main.scad new file mode 100644 index 0000000..c293d3f --- /dev/null +++ b/main.scad @@ -0,0 +1,150 @@ +/* [Main design variables] */ +variant = "stamp"; // ["stamp", "stencil"] +// Set the width of the object. Height is calculated automatically. +width = 80; // [0:200] +// Set the text size to match the width. +textsize = 12; // [10:36] +font_set = 2; // [0:"linux", 1:"windows", 2:"custom", 3:"stencil"] +font_index = 0; +lines = ["line one", "line two"]; + +/* [common technical vars] */ +linespacing_custom = 0.8; +border = 0; + +/* [stamp technical vars] */ +base_thickness_stamp = 1; +base_rounding_stamp = 4; +stamp_depth = 1.5; + +/* [stencil technical vars] */ +base_thickness_stencil = 0.4; +base_rounding_stencil = 2; + +/* [fonts] */ + +fonts_linux = [ + +]; + +fonts_windows = [ + +]; + +fonts_custom = [ + "Anonymous Pro Minus:style=Bold", + "Anonymous Pro Minus", + "Kings:style=Regular", + "CAT FrankenDeutsch:style=Regular", + "Bounded:style=Medium" +]; + +fonts_stencil = ["Depot:style=Regular", + "Depot Filled:style=Regular", + "Allerta Stencil:style=Regular", + "Stardos Stencil:style=Regular", + "Stardos Stencil:style=Bold", + "Stencilia\\-A:style=Regular", + "Stencilia\\-Bold:style=Regular" +]; + +/* [hidden] */ + +linespacing = textsize*1.6 * linespacing_custom; +height = (len(lines) * linespacing) + border*2; + +font_sets = [fonts_linux, fonts_windows, fonts_custom, fonts_stencil]; +font = font_sets[font_set][font_index]; + +if (font == undef) +{ + assert(false, "Font index out of range"); +} + + +if (version()[0] != 2021 || version()[1] != 1) +{ + echo(); + echo(); + echo(); + echo("WARNING!"); + echo("Version is not 2021.01"); + echo("Edit model text in the code editor"); + echo("pending changes in the customizer may be overwritten"); + echo(); + echo(); + echo(); +} + + +// All variables are set, make main +main(); + + +module main() +{ + if (variant == "stamp") + { + scale([-1,1,1]) + stamp(); + translate([40,0,0]) + %stamp(); + } + else if (variant == "stencil") + { + stencil(); + } + else + { + assert(false, "Invalid object variant"); + } +} + +module stamp_base(x, y, z, rounding) +{ + hull() + { + for(i = [0+rounding,x-rounding]) + { + for(j = [0+rounding,y-rounding]) + { + translate([i,j,0]) + cylinder(h = z, r = rounding); + } + } + } +} + +module stamp() +{ + union() + { + stamp_base(x = width, y = height, z = base_thickness_stamp, rounding = base_rounding_stamp); + + for (i = [0 : 1 : len(lines)]) + { + line = lines[(len(lines)-1)-i]; + translate(v = [width/2, linespacing/2 +border + i*linespacing, 0]) + color("white") + linear_extrude(height = base_thickness_stamp+stamp_depth) + text(line, font = font, halign="center", valign="center", size=textsize); + } + } +} + +module stencil() +{ + difference() + { + stamp_base(width, height, base_thickness_stencil, base_rounding_stamp); + + for (i = [0 : 1 : len(lines)]) + { + line = lines[(len(lines)-1)-i]; + translate(v = [width/2, linespacing/2 +border + i*linespacing, 0]) + linear_extrude(height = base_thickness_stencil+0.01) + text(line, font = font, halign="center", valign="center", size=textsize); + } + } +} + From 49bdada671a92ed75ca8c1785ec70bfc19ae5a87 Mon Sep 17 00:00:00 2001 From: deboxed Date: Tue, 3 Feb 2026 13:49:04 +0100 Subject: [PATCH 2/3] update stamp logic --- main.scad | 54 ++++++++++++++++++++---------------------------------- 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/main.scad b/main.scad index c293d3f..58e182d 100644 --- a/main.scad +++ b/main.scad @@ -1,16 +1,14 @@ /* [Main design variables] */ variant = "stamp"; // ["stamp", "stencil"] -// Set the width of the object. Height is calculated automatically. -width = 80; // [0:200] // Set the text size to match the width. -textsize = 12; // [10:36] -font_set = 2; // [0:"linux", 1:"windows", 2:"custom", 3:"stencil"] +textsize = 36; // [10:36] +font_set = 4; // [0:"linux", 1:"windows", 2:"custom", 3:"stencil", 4:"manual"] +font_manual = "Ubuntu:style=Bold"; font_index = 0; -lines = ["line one", "line two"]; +line = "lorem ipsum"; /* [common technical vars] */ -linespacing_custom = 0.8; -border = 0; +border = 3; /* [stamp technical vars] */ base_thickness_stamp = 1; @@ -36,7 +34,8 @@ fonts_custom = [ "Anonymous Pro Minus", "Kings:style=Regular", "CAT FrankenDeutsch:style=Regular", - "Bounded:style=Medium" + "Bounded:style=Medium", + "LT Effervescent:style=Regular" ]; fonts_stencil = ["Depot:style=Regular", @@ -50,10 +49,8 @@ fonts_stencil = ["Depot:style=Regular", /* [hidden] */ -linespacing = textsize*1.6 * linespacing_custom; -height = (len(lines) * linespacing) + border*2; - -font_sets = [fonts_linux, fonts_windows, fonts_custom, fonts_stencil]; +fonts_manual = [font_manual]; +font_sets = [fonts_linux, fonts_windows, fonts_custom, fonts_stencil, fonts_manual]; font = font_sets[font_set][font_index]; if (font == undef) @@ -62,20 +59,11 @@ if (font == undef) } -if (version()[0] != 2021 || version()[1] != 1) -{ - echo(); - echo(); - echo(); - echo("WARNING!"); - echo("Version is not 2021.01"); - echo("Edit model text in the code editor"); - echo("pending changes in the customizer may be overwritten"); - echo(); - echo(); - echo(); -} +tm = textmetrics(line, size=textsize, font=font); +width = tm.size[0]; +height = tm.size[1]; +base_position = tm.position; // All variables are set, make main main(); @@ -119,16 +107,14 @@ module stamp() { union() { - stamp_base(x = width, y = height, z = base_thickness_stamp, rounding = base_rounding_stamp); + translate(base_position) + translate([-border,-border,0]) + stamp_base(x = width+2*border, y = height+2*border, z = base_thickness_stamp, rounding = base_rounding_stamp); + + color("white") + linear_extrude(height = base_thickness_stamp+stamp_depth) + text(line, font = font, size=textsize); - for (i = [0 : 1 : len(lines)]) - { - line = lines[(len(lines)-1)-i]; - translate(v = [width/2, linespacing/2 +border + i*linespacing, 0]) - color("white") - linear_extrude(height = base_thickness_stamp+stamp_depth) - text(line, font = font, halign="center", valign="center", size=textsize); - } } } From 7f8d98ca0a95e53158d6aa43d56d9de881b4b8c2 Mon Sep 17 00:00:00 2001 From: deboxed Date: Tue, 3 Feb 2026 14:33:38 +0100 Subject: [PATCH 3/3] tweaks, add makefile --- .gitignore | 5 +++++ Makefile | 23 +++++++++++++++++++++++ main.json | 19 +++++++++++++++++++ main.scad | 21 +++++++++++---------- 4 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 main.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..193a3a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ + +*.png~ +*.deps +*.stl +*.generated.scad diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1317654 --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +# TARGETS=$(shell sed '/^module [a-z0-9_-]*().*make..\?me.*$$/!d;s/module //;s/().*/.stl/' main.scad) + + + +GENERATED_FILES = $(wildcard *.deps) \ + $(wildcard *.stl) \ + $(wildcard *.png) \ + $(wildcard *.generated.scad) + +.phony: all clean + +# all: ${TARGETS} + +include $(wildcard *.deps) + +%.stl: main.scad main.json Makefile + flatpak run org.openscad.OpenSCAD --enable textmetrics -p main.json -P $(basename $@) -DFN=64 -D "MODELVER=\"$(shell git rev-parse --short=6 HEAD)\"" -m make -o $@ -d $@.deps $< + +%.png: + flatpak run org.openscad.OpenSCAD --enable textmetrics -p main.json -P $(basename $@) -DFN=32 --render --imgsize 1600,1200 -o $@ main.scad + +clean: + rm -rf ${GENERATED_FILES} diff --git a/main.json b/main.json new file mode 100644 index 0000000..23b6641 --- /dev/null +++ b/main.json @@ -0,0 +1,19 @@ +{ + "fileFormatVersion": "1", + "parameterSets": { + "t4t": { + "base_rounding_stamp": "4", + "base_rounding_stencil": "2", + "base_thickness_stamp": "1", + "base_thickness_stencil": "0.40000000000000002", + "border": "3", + "font_index": "0", + "font_manual": "LT Effervescent:style=Regular", + "font_set": "4", + "line": "t4t", + "stamp_depth": "1.5", + "textsize": "36", + "variant": "stamp" + } + } +} diff --git a/main.scad b/main.scad index 58e182d..c6edcb5 100644 --- a/main.scad +++ b/main.scad @@ -1,7 +1,7 @@ /* [Main design variables] */ variant = "stamp"; // ["stamp", "stencil"] // Set the text size to match the width. -textsize = 36; // [10:36] +textsize = 24; // [10:36] font_set = 4; // [0:"linux", 1:"windows", 2:"custom", 3:"stencil", 4:"manual"] font_manual = "Ubuntu:style=Bold"; font_index = 0; @@ -39,7 +39,6 @@ fonts_custom = [ ]; fonts_stencil = ["Depot:style=Regular", - "Depot Filled:style=Regular", "Allerta Stencil:style=Regular", "Stardos Stencil:style=Regular", "Stardos Stencil:style=Bold", @@ -65,6 +64,10 @@ width = tm.size[0]; height = tm.size[1]; base_position = tm.position; +echo(); +echo(str("model size is x:", width, " y:", height)); +echo(""); + // All variables are set, make main main(); @@ -122,15 +125,13 @@ module stencil() { difference() { - stamp_base(width, height, base_thickness_stencil, base_rounding_stamp); + translate(base_position) + translate([-border,-border,0]) + stamp_base(width+2*border, height+2*border, base_thickness_stencil, base_rounding_stamp); + + linear_extrude(height = base_thickness_stencil+0.01) + text(line, font = font, size=textsize); - for (i = [0 : 1 : len(lines)]) - { - line = lines[(len(lines)-1)-i]; - translate(v = [width/2, linespacing/2 +border + i*linespacing, 0]) - linear_extrude(height = base_thickness_stencil+0.01) - text(line, font = font, halign="center", valign="center", size=textsize); - } } }