(*
    Render random fractal landscapes.
    Execute this cell several times until you get a nice landscape then
    execute the following cell to animate your landscape.
*)  
LEVELS=6;                        (* Smoothness level (6, 7, 8 work best)
*)
MX=2^LEVELS;                     (* Array dimensions *)
MY=MX/2;
a=Table[0,{MY+2},{MX+2}];        (* The data array *)
SeedRandom[];

getdata[ax_, ay_]:=              (* Get an array element *)
    Module[{x,y},
        x=IntegerPart[ax];
        y=IntegerPart[ay];
        Return[If[y>MY,a[[MX+1-y+1, MX-x+1]],a[[y+1, x+1]]]];
    ];

putdata[d_,ax_, ay_]:=           (* Add data to the array *)
    Module[{x,y},
        x=IntegerPart[ax];
        y=IntegerPart[ay];
        If[y>MY,
            a[[ MX+1-y+1, MX-x+1]]=IntegerPart[d], 
            a[[y+1, x+1]]=IntegerPart[d]
        ];
    ];

xheight[distortion_, width_]:=   (* Distort array values on the X axis
*)
    Module[{d, d1, d2, x, y, inc},
        inc=2 width;
        For[y=0, y<=MX-1, y+=inc,
            For[x=width+y, x<=MX, x+=inc,
                d1=getdata[x-width,y];
                d2=getdata[x+width,y];
                d=(d1+d2)/2 + Random[Integer,distortion]-distortion/2;
                putdata[d,x,y];
            ];
        ];
    ];

yheights[distortion_, width_]:=  (* Distort array values on the Y axis
*)
    Module[{d, d1, d2, x, y, inc},
        inc=2 width;
        For[x=MX, x>=1, x-=inc,
            For[y=width, y<=x, y+=inc,
                d1=getdata[x,y+width];
                d2=getdata[x,y-width];
                d=(d1+d2)/2 + Random[Integer,distortion]-distortion/2;
                putdata[d, x, y];
            ];
        ];
    ];

diagheight[distortion_, width_]:=   (* Distort array values on the
diagonal *)


    Module[{d, d1, d2, x, y, inc},
        inc=2 width;
        For[x=0, x<=MX-1, x+=inc,
            For[y=width, y<=MX-x, y+=inc,
                d1=getdata[x+y-width, y-width];
                d2=getdata[x+y+width, y+width];
                d=(d1+d2)/2 + Random[Integer,distortion]-distortion/2;
                putdata[d,x+y,y];
            ];
        ];
    ];
    
    main[]:=                        (* The main module
*)                   
        Module[{n, x, y, width, distortion},
            For[n=1, n<=LEVELS, n++,
                distortion=IntegerPart[5000/2^n];
                width=MX/2^n;
                xheight[distortion, width];
                yheights[distortion, width];
                diagheight[distortion, width];
            ];
            For[y=1, y<=MY+2, y++,       (* Make negative values zero *)
                For[x=1, x<=MX+2, x++,
                    If[a[[y,x]]<0,
                        a[[y,x]]=0,
                
                    ];
                ];
            ];
        ];
        
main[];
Show[SurfaceGraphics[a],Boxed->False]

(*
    Evaluate this cell then animate the graphic after evaluating the
    first cell.  Try the Mesh->False option.
*)
SpinShow[SurfaceGraphics[a],Boxed->False,ImageSize->{400,400}]