clear
clf

limit = 7;
%aviobj = avifile('random9','quality',100,'compression','Cinepak')
for r = 1:(2^(limit+1) - 2)
    random(r) = rand();
end

for c = .001:.001:.3
    x = [0,1,2];
    y = [0,1,0];
    for j=1:limit
        for i=1:(2^j)
            k = 2*i - 1;
            xnew(k) = x(i);
            xnew(k+1) = .5*(x(i)+x(i+1));
            xnew(k+2) = x(i+1);
            ynew(k) = y(i);
            ynew(k+1) = abs(.5*(y(i)+y(i+1))) + c*(random(i)-.5);
            ynew(k+2) = y(i+1);  
        end
        x = xnew;
        y = ynew;
    end
    plot(x,y)
    axis([0 2 0 1.5])
    axis off
    fill([x x(1) x(1)], [y y(end) y(1)], [.75 .40 0])
    whitebg([.55 1 1])
    axis([0 2 0 1.5])
    axis off
    %F(j) = getframe;
    %aviobj = addframe(aviobj,F(j));
end

%aviobj = close(aviobj);
