General Discussion > General Electronics

Oozby (Oozebane + Ruby) - an openscad precompiler language

(1/3) > >>

Bluebie:
It's not even strictly an electronics thing, but I think it's relevent to a few of you. 3D printers are super useful and increasingly affordable and reliable. I recently invested in a Makerbot Replicator 2 and I love it! Designing organic stuff in Sculptris is rad fun, and OpenSCAD is a really neat tool for making mechanical precise parts.


But the OpenSCAD language is horrible. It doesn't even have variables, and yet claims to be a programming language. Well, using functions in place of variables is a pain, and other annoying limitations like not being about to easily produce rounded rectangular prisms, weird inconsistent naming conventions, and more, have motivated me to make a cool thing:


Oozby is my experimental new language project. It's kind of in between coffeescript and markaby in how it works. You write a program, pretty similar to how you might in openscad, but with good clear syntax and all the power of ruby, and the oozby utility automatically parses, executes, and outputs the result of your program each time you save the file, making a .scad file for OpenSCAD, which automatically reloads the code and renders it as you program. It's really early days and it's full of bugs. Every time I use it I find a new bug. But It's also really exciting and just being able to make a cube with a border radius is incredible and wonderful. In the future I want to add verification features which will preemptively detect potential bugs and warn you about issues you might encounter - things which leave me scratching my head for hours in OpenSCAD. But already there are an incredible amount of features afforded, many just automatic for having used ruby! Here's a non-exhaustive list:

 *  For built in functions which take an `r` parameter like `sphere`, `circle`, `cylinder`, you can specify any of these instead:
 *  * `r`, `radius`
 *  * `r1`, `radius_1`, `radius1`
 *  * `r2`, `radius_2`, `radius2`
 *  * `d`, `dia`, `diameter`: _anything specified as diameter will be automatically halved, taking a lot of `/ 2.0` statements out of your code_
 *  * and of course `d1`, `dia1`, `dia_1`, `diameter1`, `diameter_1`, `d2`, `dia2`, `dia_2`, `diameter2`, `diameter_2`
 *  For cylinders you can specify a Range for the radius option instead of specifying r1 and r2 to make tapering shapes
 *  Built in functions which take 'h' like `cylinder` and `linear_extrude` can take `height` instead if you like
 *  Cubes and Squares have a `radius` option, which if `> 0.0` causes the corners to be rounded very cleanly.
 *  All the round things have a 'facets' option which translates to $fn
 *  No semicolons (of course!) - specify one function as the parent of the next by using a block or use the > operator (see examples)
 *  Lambda, classes, methods, oh my!
 *  Built in functions like translate, rotate, scale, which take a 2d or 3d vector [x,y,z] can instead have options passed like this:
 *  *  `translate(x: 5, y: 6)` - unspecified items default to 0
 *  *  `scale(y: 2)` - unspecified items default to 1 for scale. Smart!
 *  Specify defaults: You can create a context within a block where everything defaults to `center: true`! How many times have you had to write `center = true` again and again when constructing something with lots of symmetry in OpenSCAD?
 *  Establish a scope within a block with specific resolution settings
 *  Totally legit scope.
 *  Actual variables.
 *  All the kinds of looping, enumeration and hard core maths Ruby is capable of. It's just ruby code after all! Need a complex number? the core Complex class has you covered! Want a mathematical Matrix? The Matrix class included in the standard ruby library is here to help! Need to work with insanely big numbers? bigdecimal to the rescue!
 *  Everything in RubyGems: Parse an MP3 and print out a phonograph record! Digest an XML feed of geological data and extrude 3d shapes from it with nokogiri! Query sensor data from webcams, arduinos, microphones, buttons, joysticks, and generic usb devices! Directly read image formats with gems like ChunkyPNG and rmagick! Create automated production workflows, importing data from online store orders directly in to your printing pipeline!

So if that sounds like a rad thing, I'd love it if you help me come up with future ideas for where this should go, play with it, make cool stuff. I'm pretty excited.


Check it out over on github at https://github.com/bluebie/oozby

dougal:
I don't have a 3D printer, or even easy access to one, but I've been keeping an envious eye on that area.


Very cool, Bluebie!

Dust:
 ::)
Have you even looked at the manual for openscad?  of course it has variables

http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Variables

Bluebie:
Have you even read the manual for openscad? What they call variables are constants. You can only set them once, you can only set them at the start of a program or the start of a module - not within any ifs or loops or anything else. It is just one of uncountable quirks of openscad that they call constants "variables" despite not being able to vary their value - along with their rectangular prisms being called cubes and their rectangles being called squares.

DeuxVis:
Awesome ! You just gave me a nice reason to start using ruby.

Navigation

[0] Message Index

[#] Next page

Go to full version