Simplifying our code with modules
As we've seen, OpenSCAD code can start to become quite complex. This not only makes it more difficult to maintain but makes our coding prone to errors. An elegant way to deal with this is to break our code into modules. Although we can put any code we want into a module, it is best practice to keep a module limited to a single function. For example, a good way to break up the Thumbs Up award would be by using code to create the base, code to create the Thumbs Up symbol, and code to create the plaque.
The syntax to create a module in OpenSCAD is the word module
, followed by opening and closing parenthesis and open and closing curly braces:
module name_of_module(parameters) { body_of_module }
As we can see, modules are similar in their syntax to the difference
, union
, and intersection
operations. It is a good idea to name the modules with verbs since they perform actions.
We will start exploring modules...