Welcome! Log In Create A New Profile

Advanced

Openscad thing I made

Posted by smcameron 
Openscad thing I made
July 16, 2011 11:00AM
Hi, I'm new here.

I made this trivial little thing which you guys might find interesting that I called opencscad (note the extra 'c') which is a tiny set of little C functions which lets you easily write C code which spits out OpenSCAD code. That way you get real variables, recursion, etc. Anyway, just thought you guys might find it, if not useful, at least somewhat interesting. It would be trivial to do something similar in other languages if you wanted to.

Here's one example that was produced by 47 lines of C code:


-- steve
Re: Openscad thing I made
July 16, 2011 11:44AM
That looks cool!

fdavies
Re: Openscad thing I made
July 16, 2011 12:32PM
I don't exactly get the purpose of this. Couldn't the thing you see in the picture be constructed with openscad itself?
As for 'missing' language features in openscad... do you need recursion? what are real variables?

If you want a certain feature why not patch openscad itself? And not that openscad is a standalone system or something it basically just is a user fronted for OpenCSG.
Re: Openscad thing I made
July 16, 2011 01:38PM
Some things are easier to do when you have recursion. Any sort of fractal object is going to be tough to make in OpenSCAD because the language is not powerful enough (no recursion, no arrays, so you can't even simulate recursion with an explicit stack) That source for that tree, for example is here: tree.c. It's 47 lines of C, 976 bytes. I don't think you could come close to that with plain OpenSCAD. The output of tree.c, which is an equivalent OpenSCAD program is 38000+ lines (granted, the generated code is not the sort of code a human would produce.)

OpenSCAD variables aren't "real" because
Quote
OpenSCAD Manual
Variables are set at compile-time, not run-time

Note: Because OpenSCAD calculates its variable values at compile-time, not run-time, the last variable assignment will apply everywhere the variable is used. It may be helpful to think of them as overridable constants rather than as variables.

Would it be better to patch OpenSCAD itself than do what I did? Of course it would. I would like it very much if someone would do that. But doing that is *much* harder than what I've done, which is quite likely why nobody has done it so far, and in the mean time, what I've done allows me to get the same results more or less with very little effort.
Re: Openscad thing I made
July 16, 2011 08:00PM
Strange how solutions present themselves. I was just yesterday thinking about support material for prints, and how useful it would be to have something similar to a tree structure, rooted to the print bed with a single trunk, and then using more and more, thinner branches to support the underside of overhanging parts.

While the example you provide is actually not printable (without support itself), I do see that the tree parameters can be adjusted so that "growth" of the tree occurs only in the upward direction.
Re: Openscad thing I made
July 18, 2011 03:48PM
I've wanted to start a project with a similar idea but a different language. I realized a while back that the openscad language has a similar structure to LISP. Unless you use looping constructs things are completely declarative, compound structures are done using nesting/returns. You could turn the entire language into a subdialect of scheme and old code would be useable by changing function call syntax to use parenthesis everywhere, while immediately giving you all those other features like recursion and higher order programming.

I haven't actually gotten around to doing it, but its been on my mind for a while.
Sorry, only registered users may post in this forum.

Click here to login