Parts
The object below shows a widget that can be attached to a box so that it can be fixed with a screw. It has a parameter d
for the diameter of the screw and a parameter h
for the height or thickness. We also have a parameter w
for defining the width of the part. The value is calculated as the size of the inner diameter d
plus 2
. The part contains two blocks with objects and a subtract
operation. We can now save the object under the name Widget
. The first two lines with the var
statement define the parameters for this part. The var
statements that follow a blank line are internal variables.
The Widget
can now be used in another object by using the function part
. The first argument is the name of the part and the following numbers are the parameters for this part. In this case there are two parameters d
and h
. Note that the turn
statement in the for
statement includes a rotation that includes a multiplication with the iteration variable i
. This is because the transformations are inside a block statement and are therefore reset every time the block is executed.