OpenSCAD and randomness

A quick google search tells me that OpenSCAD doesn’t have a random number generator.  That’s a bit of a bummer.  I was just thinking how cool it would be to have an OpenSCAD file that would give you little variations on itself every time you generated an STL.  I’m thinking snowflakes, giant fingerprints, and other things that have a little bit of chance and chaos built in.

Or, perhaps some kind of Mad Libs-esque system where you tell it to create an alien or monster figure and you get a random number of eyes, heads, noses, arms, legs, and tails.

Now, I figure with CloudSCAD it wouldn’t be terribly difficult to add a little bit of javascript that can include a random number with given parameters…  So, it’s at least possible.

7 thoughts on “OpenSCAD and randomness

  1. You can also call OpenSCAD from the command line!

    This lets you generate a whole .scad file from an external script before running it in OpenSCAD.

    Nickel for Scale generates customized rings by putting the measurements into an include file, which is loaded by the OpenSCAD script when rendering.

  2. @Marty: That’s interesting. I suppose I could generate a .scad file from PHP, using PHP random functions, import into OpenSCAD, then do cool stuff.
    Nickle for Scale? What’s that about?

  3. Nickel for Scale is a Processing app that uses a webcam to take an image of something to measure (e.g., a hand) and a reference object of a known size (e.g., a nickel), and allows you to take measurements from the image. These measurements are then fed into OpenSCAD to produce parameterized models such as rings.

    Nickel for Scale is open source and could be used for lots of neat stuff, so folks should check it out: http://nickelforscale.com/

    [Disclosure: I am totally on the development team for Nickel for Scale.]

  4. This should be in the next version I believe, see: http://gitorious.org/openscad/openscad/commit/d479fca855688c92f4a9f72f4ec18d655c3b351d

    Also, you can set variables on the command line like this:
    http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_OpenSCAD_in_a_command_line_environment So you could set a variable to a random value in a shell script too.

    Unfortunately, since variables aren’t really variable in openscad, it’s often easier to write code in another language that writes out openscad code. :(

  5. I read on the openscad mailinglist that a rand() function was implemented for the new version.

  6. Pingback: The cake was a lie | MakerBlock

Comments are closed.