OpenSCAD metaprograming in C
2011-07-04: OpenSCAD is a pretty cool little program and I’ve been using it for awhile now. One thing that has bugged me about it though is that the language is kind of lame. For example, there are variables — sort of. You can set them, but only the last one in the program has any effect. So they don’t really act like real variables. The looping structures are sort of tacked on to deal with this fact (I think). There is no recursion. This last one is painful if you want to think about making fractal models.
It occurred to me that because the OpenSCAD language is so simple and so C-like (at least superficially), it is trivial to write a little C library to emit OpenSCAD code. Then, you can program in C, a “real” language with real variables, types, functions, recursion, etc. and it will still look (mostly) like OpenSCAD code.
So that’s what I did. I made a little library and called it opencscad. There are probably other, better attempts to do the same thing, or similar things. I know someone’s tried a similar thing with python, for example.
Anyway, here are a couple of pics that I made with the help of this tiny library:
Fort fractal was produced by this code.
Recursive rook was produced by this code.
~ by scaryreasoner on July 4, 2011.