function snow ()
    clf; axis equal
    title 'triadic Koch curve by Allen'
    
    n = 4;
    
    v1 = [0,0];
    v2 = [0.5 ,sqrt(3)/2];
    v3 = [1,0];
    
    draw_snow (v1, v2, n)
    draw_snow (v2, v3, n)
    draw_snow (v3, v1, n)
    
function draw_snow (v1, v2, n)
    v = v2 - v1;
    length = norm (v);

    if n == 0
        drawline (v1, v2);
        return
    end
    
    p1  = v1 + v / 3;
    p2  = v1 + 2 * v / 3;
    
    p3  = v1 + v / 2;
    height = length/3 * sqrt(3)/2;
    p4 = p3 + height * normalize (perp (v));
    
    draw_snow (v1, p1, n-1);
    draw_snow (p2, v2, n-1);
    draw_snow (p1, p4, n-1);
    draw_snow (p4, p2, n-1);


function vp = perp (v)
    vp = [-v(2), v(1)];
    
function vn = normalize (v)
    vn = v / norm (v);
    
function drawline (v1, v2)
    z = [v1;v2];
    line (z(:,1), z(:,2))
