Modules as Operators

A powerful and often ignored feature of Openscad is that modules can also behave as if they were operators, exactly like the translate()or color() operators. They do not create shapes on their own, but they modify the subsequent commands. post

Here I test my understanding by defining a poke operator that inserts its first geometry through all subsequent geometry.

poke() { cylinder(30, 0, 10, true); translate([0,0,0]) cube([40,40,3],true); translate([0,0,6]) cube([40,40,3],true); }

//scad.fed.wiki/assets/viewstl/viewstl.html?stl=http://scad.fed.wiki/assets/modules-as-operators/poke.stl HEIGHT 370

We define a module that expands its children, some children over and over to make the gap for the first child to pierce the remainder.

module poke () { children(0); for(i=[1:$children-1]) { difference() { children(i); scale(1.5) children(0); } } }

modules-as-operators