Skip to content

Instantly share code, notes, and snippets.

@calebhsu
Last active August 30, 2015 15:19
Show Gist options
  • Save calebhsu/e5bb4cc3eaa28023a3f5 to your computer and use it in GitHub Desktop.
Save calebhsu/e5bb4cc3eaa28023a3f5 to your computer and use it in GitHub Desktop.
Dresser using CraftML tags
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>
<craft name="dresser">
<param name="length" type="int" default="40"/>
<param name="width" type="int" default="15"/>
<param name="drawers" type="int" default="4"/>
<col spacing="-9" l="alignZ(50%)">
<!-- Frame -->
<cube size="{{length}} {{width}} {{(drawers*10)+drawers+5}}"/>
<col l="alignZ(50%)">
<!-- Drawers -->
<stack spacing="1">
<repeat n="{{drawers}}">
<cube size="{{length - 6}} 10 10"/>
</repeat>
</stack>
<!-- Knobs -->
<row spacing="{{length - 15}}" color="white">
<repeat n="2">
<stack spacing="9">
<repeat n="{{drawers}}">
<sphere radius="1" t="scale(1,0.8,1)"/>
</repeat>
</stack>
</repeat>
</row>
</col>
</col>
</craft>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment