Skip to content

Instantly share code, notes, and snippets.

@doubleshow
Forked from calebhsu/README.md
Last active August 29, 2015 14:26
Show Gist options
  • Save doubleshow/3be8f15b532499484a31 to your computer and use it in GitHub Desktop.
Save doubleshow/3be8f15b532499484a31 to your computer and use it in GitHub Desktop.
Chair using CraftML tags
title author
Making a Chair
Caleb Hsu

Objective: Make a chair with adjustable length and leg height.

Start by making the seat of the chair. We can add parameters after we have determined our dimensions.

<craft>
    <cube size="15 15 2"></cube>
</craft>

Next, make the back of the seat by spacing two supports with <col>. To make the rounded back, <stack> and a <cylinde>r over a sized <cube>, then combine with the supports using <stack>.

<craft>
    <stack spacing="-13">
        <stack spacing="-4">
            <cylinder height="1" radius="6" transform="
                rotateY(90)
            "></cylinder>
            <cube size="1 11 7.5"></cube>
        </stack>
            
        <col spacing="11">
            <repeat n="2">
                <cube size="2 2 15"></cube>
            </repeat>    
        </col>
    </stack>
</craft>

Finally, make the legs by using <col> and <repeat> on a group <g> of two legs and a horizontal support. Consider how spacing and size affect their relation to the width and length of the seat.

<craft>
    <col spacing="11">
        <repeat n="2">
            <g layout="lineupX() alignZ(20%)">
                <cube size="2 2 14"></cube>     
                <cube size="11 1.5 1.5"></cube>
                <cube size="2 2 14"></cube>
            </group>
        </repeat>
    </col>
</craft>

Group and layout the legs, seat, and back together, using the align, lineup and center functions.

<craft>
    <g layout="alignX(0%) lineupZ(0) centerY()">
        <stack>
            <cube size="15 15 2"></cube>
            
            <col spacing="11">
                <repeat n="2">
                    <g layout="lineupX() alignZ(20%)">
                        <cube size="2 2 14"></cube>     
                        <cube size="11 1.5 1.5"></cube>
                        <cube size="2 2 14"></cube>
                    </group>
                </repeat>
            </col>
        </stack>
        
        <stack spacing="-13">
            <stack spacing="-4">
                <cylinder height="1" radius="6" transform="
                    rotateY(90)
                "></cylinder>
                <cube size="1 11 7.5"></cube>
            </stack>
            
            <col spacing="11">
                <repeat n="2">
                    <cube size="2 2 15"></cube>
                </repeat>    
            </col>
        </stack>
    </g>
</craft>

Now that we've finalized our dimensions, parameterize seat length and leg height.

<craft name="chair">
    <parameter name="length" type="int" default="15"/>
    <parameter name="legHeight" type="int" default="14"/>
    
    <stack layout="alignX(0%)" color="peru">
        <stack spacing="-13">
            <stack spacing="-4">
                <cylinder height="1" radius="6" 
                    transform="rotateY(90)
                "></cylinder>
                <cube size="1 11 7.5"></cube>
            </stack>
            
            <col spacing="11">
                <repeat n="2">
                    <cube size="2 2 15"></cube>
                </repeat>    
            </col>
        </stack>
        
        <stack>
            <cube size="{{length}} 15 2"></cube>

            <col spacing="11">
                <repeat n="2">
                    <row layout="alignZ(20%)">
                        <cube size="2 2 {{legHeight}}"></cube>     
                        <cube size="{{length - 4}} 1.5 1.5"></cube>
                        <cube size="2 2 {{legHeight}}"></cube>
                    </row>
                </repeat>
            </col>
        </stack>
    </stack>
    
</craft>
<craft name="chair">
<parameter name="length" type="int" default="15"/>
<parameter name="legHeight" type="int" default="14"/>
<stack layout="alignX(0%)" color="peru">
<!-- Back -->
<stack spacing="-13">
<stack spacing="-4">
<cylinder height="1" radius="6"
transform="rotateY(90)
"></cylinder>
<cube size="1 11 7.5"></cube>
</stack>
<col spacing="11">
<repeat n="2">
<cube size="2 2 15"></cube>
</repeat>
</col>
</stack>
<stack>
<!-- Seat -->
<cube size="{{length}} 15 2"></cube>
<!-- Legs -->
<col spacing="11">
<repeat n="2">
<row layout="alignZ(20%)">
<cube size="2 2 {{legHeight}}"></cube>
<cube size="{{length - 4}} 1.5 1.5"></cube>
<cube size="2 2 {{legHeight}}"></cube>
</row>
</repeat>
</col>
</stack>
</stack>
</craft>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment