Paul Peng

23 Jan 2014

Twitter Summary: @1732051 makes something dumb using #OpenSCAD and cylinders


For this project, I began with the idea of creating compartments in a grid formation where a certain repeating element will be altered based on its position in this grid through some mathematical function. Eventually I had this grid wrap around so that it formed a cylindrical shape. In commemoration of this cylindrical grid I made the repeating element a cylinder as well.


Above is what this cylinder of cylinders looks like without any modifications. This thing takes a really long to compile!

Screen Shot 2014-01-23 at 12.14.18 AM

The parameters that one would run the function itself include the height of the collection of cylinders, its vertical offset from the center, and the number of rows and columns to include. In addition, a section of the module consisting of various function definitions can be edited by the client to determine the radius of the super-cylinder at a given sub-cylinder and the color, length, and radius of each sub-cylinder based on some mathematical formula involving the row and column of that sub-cylinder. This can be used to produce some pretty nice looking things.

Screen Shot 2014-01-23 at 12.02.33 AM

The main issue I had with OpenSCAD while making this is the fact that it does not seem to support higher-order functions, which would make the implementation of this significantly more elegant since the client would not have to write directly in the module where the guts of the implementation lie. In addition, to render multiple super-cylinders one would have to copy-and-paste the module and give it a different name. Yuck!


I also chose to work in and take my screencaps from since the version of openSCAD I downloaded seemed to render everything in this nice but unchangeable yellow tone, regardless of how many times you call color(). It also seemed to take longer to render the images as well and didn’t produce particularly high-resolution images when I would ask it to export the file as an image. Whatever! I do what I want! Here are some sketches.

img009 img010

Ignore where it says “ultimate fucker” in all caps on that first page of sketches; that’s for a painting I might make later this year. Here’s one more thing I made with my thing.


Interesting? Beautiful? Maybe, but definitely useless. You can’t really 3-D print this either. Nevertheless, it produced some results that I found surprisingly elegant, and is something I would love to use again and take even further if not for OpenSCAD’s inflexibility towards certain things (higher order functions!) and the ridiculously long time it takes to compile for anything relatively large. I will upload this to GitHub and Thingiverse when it’s not 1 in the morning so I can actually show up to this class today Here’s the GitHub link; Thingiverse is coming later.

/* this is my cylinder thing. (my = paul peng)
 * higher order functions are not supported
 * this programming language is shit >_<
 * To use, copy supercyl_template and change name to something like
 * "supercyl_a" or something. Change the functions inside s.t. you get
 * cool variations in the way things happen.
 * To draw multiple supercylinders copy the template and give it
 * a different name like "supercyl_b".
 * This would be so much easier with higher order functions :(
 * modified sin and cos for convenience
 * input goes from 0 to 1 instead of 0 to 360
 * output goes from 0 to 1 instead of -1 to 1
function mysin(n) = 0.5 + 0.5*sin(n);
function mycos(n) = 0.5 + 0.5*cos(n);
module supercyl_template(h, zoffset, rows, cols) {
    /* user-defined functions, feel free to change */
    /* note: arguments passed are value in range [0, 1) */
    function radfun(row, col) = 25;
    function colorfun(row, col) = [0.5, 0.5, 0.5];
    function nibhfun(row, col) = 6;
    function nibrfun(row, col) = 3;
    /* don't change anything after this */
    rowspace = h / rows;
    colang = 360 / cols;
    for (row = [0 : rows-1]) {
        for (col = [0 : cols-1]) {
            //color(colorfun(row/rows, col/cols))
            rotate([0, 0, colang * col])
            translate([0, radfun(row/rows, col/cols), zoffset - h/2 + rowspace * row + rowspace/2])
            rotate([90, 0, 0])
            cylinder(h = nibhfun(row/rows, col/cols), r = nibrfun(row/rows, col/cols), center = true);
/* delete this when you put your own stuff in */
supercyl_template(75, 0, 2, 20);