title | author |
---|---|
Building a Dresser |
Caleb Hsu |
Objective: Build a dresser of n drawers. The drawers will be stacked on each other within a rectangular frame.
Let's begin by making the frame. We can add parameters after we have determined our dimensions.
<craft>
<cube size="40 15 49" color="brown"></cube>
</craft>
Stack
drawers and center on the z axis using centerZ()
.
<craft>
<col spacing="-9" layout="centerZ()">
<cube size="40 15 49" color="brown"></cube>
<stack spacing="1">
<repeat n="4">
<cube size="34 10 10"></cube>
</repeat>
</stack>
</col>
</craft>
Add drawer knobs by spacing and stacking each pair using row
and stack
, respectively. Align with the frame using col
, again centering on the z axis.
<craft>
<col spacing="-9" layout="centerZ()">
<cube size="40 15 49" color="brown"></cube>
<col layout="centerZ()">
<stack spacing="1" color="peru">
<repeat n="4">
<cube size="34 10 10"></cube>
</repeat>
</stack>
<row spacing="25">
<repeat n="2">
<stack spacing="9">
<repeat n="4">
<sphere radius="1" transform="scale(1,0.8,1)"></sphere>
</repeat>
</stack>
</repeat>
</row>
</col>
</col>
</craft>
Now that we've finalized the dimensions, parameterize dresser width, depth, and number of drawers.
<craft name="dresser">
<parameter name="length" type="int" default="40"/>
<parameter name="width" type="int" default="15"/>
<parameter name="drawers" type="int" default="4"/>
<col spacing="-9" layout="centerZ()">
<cube size="{{length}} {{width}} {{(drawers*10)+drawers+5}}" color="brown"></cube>
<col layout="centerZ()">
<stack spacing="1" color="peru">
<repeat n="{{drawers}}">
<cube size="{{length - 6}} 10 10"></cube>
</repeat>
</stack>
<row spacing="{{length - 15}}" color="white">
<repeat n="2">
<stack spacing="9">
<repeat n="{{drawers}}">
<sphere radius="1" transform="scale(1,0.8,1)"></sphere>
</repeat>
</stack>
</repeat>
</row>
</col>
</col>
</craft>