Skip to content

Instantly share code, notes, and snippets.

@calebhsu
Last active August 30, 2015 15:19
Show Gist options
  • Save calebhsu/be2c23fdad510ebbbafc to your computer and use it in GitHub Desktop.
Save calebhsu/be2c23fdad510ebbbafc to your computer and use it in GitHub Desktop.
Picket fence using CraftML tags
title author
Building a Picket Fence
Caleb Hsu

Objective: Build a picket fence with adjustable length and height.

Start by creating a row of picket boards. We can add parameters after we have determined our dimensions.

<craft>
    <row spacing="5">
        <repeat n="6">
            <cube size="5 3 40" color="wheat"></cube>
        </repeat>
    </row>
</craft>

Next, create triangular picket spikes using prism .

<craft>
    <row spacing="5">
        <repeat n="6">
            <prism width="5" length="3"></prism>
        </repeat>
    </row>
</craft>

Stack the spikes over the boards to make pickets

<craft>
    <stack>
        <row spacing="5">
            <repeat n="6">
                <prism width="5" length="3"></prism>
            </repeat>
        </row>
        
        <row spacing="5">
            <repeat n="6">
                <cube size="5 3 40" color="white"></cube>
            </repeat>
        </row>
    </stack> 
</craft>

Next, stack two boards to create the rails.

<craft>
    <stack spacing="13" transform="translate(0,0,8)">
        <repeat n="2">
            <cube size="55 2 5"></cube>
        </repeat>
    </stack>
</craft>

Combine rails with pickets to complete the fence. Feel free to experiment with positioning until the fence looks right.

<craft>
    <g>
        <stack spacing="13" transform="translate(0,0,8)">
            <repeat n="2">
                <cube size="55 2 5"></cube>
            </repeat>
        </stack>
            
        <stack color="wheat">
            <row spacing="5">
                <repeat n="6">
                    <prism width="5" length="3"></prism>
                </repeat>
            </row>
            
            <row spacing="5">
                <repeat n="6">
                    <cube size="5 3 40"></cube>
                </repeat>
            </row>
        </stack>     
    </g>
</craft>

Now that we've finalized the dimensions, parameterize picket height and fence length.

<craft name="fence">
    <parameter name="length" type="int" default="55"/>
    <parameter name="height" type="int" default="40"/>
    
    <group color="wheat">
        <stack spacing="{{height / 3}}" transform="translate(0,0,{{height/6}})">
            <repeat n="2">
                <cube size="{{length}} 2 5"></cube>
            </repeat>
        </stack>
        
        <stack>
            <row spacing="5">
                <repeat n="{{length / 10}}">
                    <prism width="5" length="3"></prism>
                </repeat>
            </row>
            
            <row spacing="5">
                <repeat n="{{length / 10}}">
                    <cube size="5 3 {{height}}"></cube>
                </repeat>
            </row>
        </stack>        
    </group>
    
</craft>
<craft name="fence">
<param name="length" type="int" default="55"/>
<param name="height" type="int" default="40"/>
<style>
* { color: chocolate; }
</style>
<!-- Rails -->
<stack spacing="{{height/3}}" t="translate(0 0 {{height/6}})">
<repeat n="2">
<cube size="{{length}} 2 5"></cube>
</repeat>
</stack>
<!-- Pickets -->
<stack>
<!-- Spikes -->
<row spacing="5">
<repeat n="{{length / 10}}">
<prism sideLength="5" height="3" t="rotateX(90) scale(1 1 0.7)"></prism>
</repeat>
</row>
<!-- Boards -->
<row spacing="5">
<repeat n="{{length / 10}}">
<cube size="5 3 {{height}}"></cube>
</repeat>
</row>
</stack>
</craft>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment