Random Mountain Range Generator

by Liz Schraffenberger

The Code

aRandomnumber[z_] := 
        Module[{zz = z}, 
zz = 
            Random[Real, {-z, z}, 3]; 
Return[
            zz];
];
stepOne[initialList_ , d_, xx_, z_]:=Module[{x = xx, flatList},
(*this inserts one row of diamond values*)
flatList=Flatten[d];
Sqrt[
                Length[Flatten[initialList]]];
Do[
flatList = 
                  Insert[flatList, aRandomnumber[z], 
                    x]; 
x = 
                  x + 1;
, {Sqrt[
                      Length[Flatten[initialList]]] - 1}];
Return[flatList];
];
stepTwo[initialList_, z_] := 
        Module[{flatList, xx, y, 
            d}, 
 (*this inserts diamond values for the whole list*) 
flatList = 
            Flatten[initialList]; 
xx = 
            Sqrt[Length[Flatten[initialList]]] + 1; 
d = 
            initialList; 
While[
xx <= (Length[flatList] - Sqrt[Length[Flatten[initialList]]] + 
                  1), 
flatList = 
              stepOne[initialList, d, xx, z]; 
d = 
              flatList; 
xx += 
              2 Sqrt[Length[Flatten[initialList]]] - 
                1;
]; 
Return[
            flatList];
];
stepThree[initialList_, z_] := 
        Module[{diamondList, 
            g}, 
  
diamondList = 
            stepTwo[initialList, z]; 
g = 
            2; 
While[
g <= 
              Length[diamondList], 
diamondList = 
              Insert[diamondList, aRandomnumber[z], g]; 
g += 
              2;]; 
Return[
            Partition[diamondList, 
              Sqrt[Length[
                  diamondList]]]];
];
stepFourall[initialList_, f_, k_, zz_] := 
        Module[{y, z = zz}, 
y = 
            initialList; 
Do[
Show[
              SurfaceGraphics[stepThree[y, z], 
                ViewPoint -> {3 k, -5 k, 
                    2 k}]]; 
z = 
              1/4  z; 
y = 
              stepThree[y, 
                z];
, {f}];
];
stepFourlast[initialList_, f_, zz_] := 
        Module[{y, z = zz}, 
y = 
            initialList; 
Do[
y = 
              stepThree[y, z]; 
z = 
              1/4  z;
, {f}]; 
Return[
            y];
];
zoomyPartOne[] := 
        Module[{q}, 
  
q = 
            Re[Table[(Sqrt[π - (x^2)]), {x, -1.75, 
                  1.75,  .05}]]; 
Return[
            q];];
zoomyPartTwo[] := 
        Module[{listy, n, 
            e}, 
 (*inserts x values*) 
listy = zoomyPartOne[]; 
n = 
            1; 
e = -1.75; 
Do[
listy = Insert[listy, e, n]; 
n += 
              2; 
e +=  .05;
, {Length[
                zoomyPartOne[]]}]; 
Return[
            listy];
];
zoomyPartThree[] := 
        Module[{listy, 
            f}, 
  
listy = zoomyPartTwo[]; 
f = 
            2; 
Do[
listy = 
              Insert[listy, 2, f]; 
f += 
              3;
, {Length[
                zoomyPartOne[]]}]; 
Return[
            listy];
];
zoomyPartFour[f_] := 
        Module[{r, d, i, c, q, b}, 
i = 
            1; 
r = 
            Partition[zoomyPartThree[], 3]; 
c = 
            stepFourlast[{{2, 2}, {2, 2}}, f, 5]; 
q = 
            1; 
b = -1; 
While[
i ≤ 
              Length[Partition[zoomyPartThree[], 3]], 
d = 
              Part[r, i]; 
Show[SurfaceGraphics[c], 
              ViewPoint -> 
                d, 
LightSources -> {{{b, b, b}, 
                    RGBColor[1, 0, q]}, {{q, b, q}, 
                    RGBColor[1, 1, 1]}, {{q, q, q}, 
                    RGBColor[ .2, 1, 
                      q]}}, 
DefaultColor -> 
                RGBColor[0, 0, 
                  0]]; 
i++; 
q -=  .014; 
b +=  .01;
];
];

The Result

Welcome to the Random Mountain Range Generator (patent pending). To run the program, please type in "zoomyPartFour[x]", where x is a positive whole number, press and hold shift, and press enter. The program runs fastest if x is 6 or less.