0

OpenSCAD For-Loop Project

Design No.1

 

Design No.2

 

Design No.3

The first three images are screenshots of my design. You will notice that every image is different, and this is because I used random number generation to rotate and transform my basic shape, a rectangular prism, in unpredictable ways. Hence, every time I hit the render or preview button, the design shown is completely new and unique. A screenshot of my annotated code and an explanation of it is featured below.

To create these designs, I selected a basic shape to manipulate (in this case, a rectangle) and how many copies of it I wanted. To that end, I wrote the code for the rectangle in a for loop that iterates to 10. This would create 10 rectangles.

Next, I had to decide how to manipulate the rectangles. I decided I would rotate them around all axes and translate them randomly. OpenSCAD thankfully has random-number-generating and rotation and translation functions, so I didn’t have to make my own. I simply used the random function to create values for the angles and movements along the x-, y-, and z-axis.

Due to how I coded this, the translations occur before the rotations, but I don’t think that order effects the design’s appearance. (However, I could be wrong.) Additionally, this code is extremely simple and modifable, so someone could easily change the shape being altered. Moreoever, one could even change the dimensions of the shapes involved by randomizing their dimensions, or using functions to otherwise alter them, or even randomizing the values given to those said functions, and so on and so forth.

The one problem I experienced with this program was the use of the random function. It works weirdly in that it can’t, in my experience, be passed to functions that accept integers/numbers themselves, but it can be passed to integers which can be passed to functions that accept integer values. To solve this, I created the integer variables a, b, c, and x, y, z to accept the randomly generated values and be used in funtions.

turnermb

Leave a Reply

Your email address will not be published. Required fields are marked *