Documentation for Liz 
Schraffenberger' s final project

I decided to cut my teeth on solving the problem of intruducing fractal growth in two dimensions .  
            If I could creat a randomized horizon line, I believed I would have the basic tools to carry on 3D work .  Once that was mastered, I moved on to working with 3 dimensions using a Diamond Array algorithm .  
            Below are the versions and attempts I made, in chronological order, with original comments. Any comments added  to subsections during the creation of this notebook are highlighted in yellow.

2d Fractal practice
Goals:
-To create a program that will create a mountainous horizon line. I figure working out how to infuse a line with randomness will be an easier task than jumping straight into a 3d realm.
This version works, but it's ungainly. This was created before I was comfortable putting smaller programs in larger ones, so the end result is a massive program full of basic functions.

Show[Graphics[Line[{{1, 0}, {50, 0}}]]]

⁃  Graphics  ⁃

\(\(\( (*so\ far, \ so\ good . \ Now, \ 
      we\ have\ to\ create\ a\ function\ that\ will\ find\ the\ midpoint\ of\ a\ line . \ 
          The\ equation\ for\ finding\ the\ midpoint\ of\ a\ line\ is\ \(\((\((x\_\(\([[\)\(2\)\(]]\)\) - 
                  x\_\(\([[\)\(1\)\(]]\)\))\)/2, \ \((y\_\(\([[\)\(2\)\(]]\)\) - 
                  y\_\(\([[\)\(1\)\(]]\)\))\)/2)\)\(.\)\)*) \)\(
\)\(midPoint[a_, 
        b_] := 
Do[
\(Return[\ 
            Abs[\((a - b)\)/2]];\)
]\)\)\)

\(\(\(midPoint[1, 2]\)\(
\)\(
\)
    \)\)

\(Clear[midPoint]

      midPoint[a_, b_, c_, d_] := 
Return[\ 
          Abs[\((a - b)\)/2], \ \(Abs[\((c - d)\)/2];\)
]

      midPoint[1, 2, 5, 8]\)

\(\(\(
\)\( (*It\ doesn' 
        t\ work\ if\ I\ put\ seperate\ Return\ into\ two\ different\ functions, \ 
      either*) \)\(
\)\(\(midPoint[a_, b_, c_, 
          d_] := 
Return[\ Abs[\((a - b)\)/2]];\)

    \(Return[\ Abs[\((c - d)\)/2]
];\)\)\)\)

Clear[
      midPoint]

Flatten[{{1, 2}, {3, 
          4}}]

Partition[%, 2]

\(\(line = {{1, 2}, {3, 4}};\)

      \({{1, 2}, {3, 4}};\)

      midPoint[
          line_] :=  (*\(Module\)\([\)\({};\)*) 
Flatten[
          line]


      midPoint[line]

      \)

(*manipulating the string:
This was way, way more complicated than I had anticipated!
in order to get the midpoint of every line segment, we need to compare the n and n + 
            2 (the first two x values) and  n + 1 and n + 
            3 (the first two y values), and make those two results the start of a new list .  Then we need to compare the n + 2 and n + 
            4 values and the n + 3 and n + 
            5 values .  Then we need to compare the n + 4 and n + 
            6, and n + 5 with n + 
            7. 


          So, basically, we need one function that will compare two sets of numbers :  n and n + 2, and n + 1 and n + 
            3.  The two results x and y will be inserted between n + 1 and n + 
            2.  This program needs to be incremented by 2.  When we run out of numbers, the output list will be partitioned by 2*)
\(\(line = {{1, 2}, {4, 
              5}};\)


      \(newList = Flatten[line];\)


      First[newList]\)

\(\(\(
\)\(Part[newList, 3]\)\)\)

\(\(\(
\)\(\((Part[newList, 1] + Part[newList, 3])\)/2\)\)\)

\(\(\(
\)\(Part[newList, 2]\)\)\)

\(\(\(
\)\(Part[newList, 4]\)\)\)

\(\(\(
\)\(\(\((Part[newList, 2] + Part[newList, 4])\)/
      2\)\(
\)
    \)\)\)

\(\(\(Insert[newList, \ \((Part[newList, 1] + Part[newList, 3])\)/2, 
      3]\)\(
\)
    \)\)

Insert[%, (Part[newList, 2] + 
            Part[newList, 4])/2, 4]

Partition[%, 2]

\(\(\(
\)\(Clear[newList]

    Clear[line]

    Clear[midPoint]\)\)\)

\({{1, 2}, {5, 7}}

      \(midPoint[line_] := 
          Module[{newList, n}, 
newList = 
              Flatten[line]; 
n = 
              1; 
Print["The new list is " <> 
                ToString[newList]]; 
newList = 
              Insert[
newList, \ \((Part[newList, n] + 
                      Part[newList, n + 2])\)/2, 
                3]; 
newList = 
Print["the new list is now " <> 
                  ToString[newList]];
];\)\)

list = {{1, 3}, {5, 7}}
midPoint[list]

\(
\)

Clear[list]

midPoint[line_] := 
        Module[{newList, n}, 
newList = 
            Flatten[line]; 
n = 
            1; 
Print["The new list is "[
              newList]]; 
newerList = 
            Insert[
newList,  (Part[newList, n] + 
                    Part[newList, n + 2])/2, 
              3]; 
Print["the newer list is now "[
              newerList]]; 
newestList = 
            Insert[
newerList, (Part[newList, n + 1] + 
                    Part[newList, n + 3])/2, 
              4]; 
Print["The newest list is now "[
              newestList]]; 
Return[
            Partition[newestList, 2]];
];

list = {{3, 5}, {7, 9}}

midPoint[list]

midPoint[line_]:=Module[{newList, n, x},
newList = Flatten[line];
n = 1;
x = 3;
Do[
  
  
If[
n + 2 > 
                        Length[newestList], 
  
                        Break[]
  
];
newerList = 
                      Insert[
newList,  (Part[newList, 
                                n] + Part[newList, n + 2])/2, x];
  
  
newestList = 
                      Insert[
newerList, (Part[newList, 
                                n + 1] + Part[newList, n + 3])/
                          2, (x + 1)];
  
  
newList = newestList;
(*Print["The updated original flattened \
list is "[newList]];*)
newerList = newestList;
  
n += 4;
x += 4
,{(Length[Flatten[line]]/2) - 1}
];
Return[Partition[newestList, 2]];
];

list = {{1, 2}, {2, 3}, {3, 4}}

midPoint[list]

midPoint[%]

midPoint[%]

randomPoint[line_]:=Module[{newList, n, x},
newList = Flatten[line];
n = 1;
x = 3;
Do[
  
  
If[
n + 2 > 
                        Length[newestList], 
  Brea 
                         k[]
];
newerList = 
                      Insert[
newList,  (Part[newList, 
                                n] + Part[newList, n + 2])/2, x];
  
  
newestList = 
                      Insert[
newerList, 
                        Random[Real, {5, 20}, 2], (x + 1)];
  
  
newList = newestList;
(*Print["The updated original flattened \
list is "[newList]];*)
newerList = newestList;
  
n += 4;
x += 4
,{(Length[Flatten[line]]/2) - 1}
];
Return[Partition[newestList, 2]];
];

thing = {{0, 10}, {20, 10}}

randomPoint[thing]

randomPoint[%]

randomPoint[%]

randomPoint[%]

randomPoint[%]

randomPoint[%]

Show[Graphics[Line[%]]]

Clear[thing]

Mountains - Part one
This one really doesn' 
        t go anywhere .  
          I was strugging with a way to increment different parts of the program different numbers of times .  
          I was really unclear as to how to use modules to their full advantage.

randomPoint[line_]:=Module[{newList, n, x},
newList = Flatten[line];
n = 1;
x = 3;
y = 20;
Do[
Do[
  
newerList = 
                          Insert[
newList,  (Part[
                                    newList, n] + Part[newList, n + 2])/2, 
                            x];
  
newestList = 
                          Insert[
newerList, 
                            Random[Real, {10, y}, 2], (x + 1)];
  
newList = 
                          newestList;
Print["newestList's length \
is " <> ToString[Length[newestList]]];
n += 4;
Print["n is now "[n]];
x += 4;
Print["x is now "[x]];
If[
n + 2 > 
                            Length[newestList], 
  
                            Break[]
];
,{(Length[Flatten[line]]/2) - 1}
];
n = 1;
x = 3;
y = y/2;
  
,{2}];
Return[Partition[newestList, 2]];
];

thing = {{0. , 10}, {20, 10}}

randomPoint[thing]

Clear[simpleAdd]
(*simpleAdd was a program I created to add two numbers together (deleted from this notebook after trying to run multiAdd) .  I then created multiAdd, which uses simpleAdd .  
                I was trying to figure out how to put smaller programs into larger ones, with little success .  I still hadn't quite grasped the idea of how to use Modules to their fullest extent*)

multiAdd[x_] := 
      Module[{z}, 
z = 
          Plus[x, 1]; 
Do[
simpleAdd[
            x]; 
Print["z is "[
              z]];
, {2}]; 
Return[
          z];
]

multiAdd[2]

terrain = Table[1 - 2, {1}, {2}];

terrain

Mountains  - Part two (The Wrath of Khan)
 \(A\ reworking\ of\ 2  
            D\ fractal\ practice . \ 
              This\ is\ where\ I\ learned\ how\ to\ use\ subprograms\ and\ modules\ to\ their\ fullest\ extent . \ 
              You\ know\ that\ scene\ in\ "The Miracle Worker"\ where\ Helen\ Keller\ learns\ how\ to\ sign\ "water"?\ Yeah\), it was like that.

flattenedList = Flatten[thing]

thing = {{0, 0}, {10, 0}}

flattenedList

Clear[theList]

\(insertX[flattenedList_, x_, n_] := 
      Module[{newerList}, 

        newerList = 
          Insert[
flattenedList, \ \((Part[flattenedList, 
                    n] + Part[flattenedList, n + 2])\)/2, 
            x]; 
Return[
          newerList];
]\)

insertX[{0, 0, 30, 0}, 3, 1]

insertY[newerList_, x_, y_] := 
      Module[{newestList}, 
newestList = 
          Insert[
newerList, 
            Random[Real, {-y, y}, 
              2], (x + 1)]; 
Return[
          newestList];
]

insertY[{0, 0, 15, 30, 0}, 3, 20]

thing

newerList

newestList

randomMidpoints[z_, y_]:=Module[{n, x},
  
n = 1;
x = 3;
theList = Flatten[z];
While[
n + 2 < 
                Length[theList], 
  
theList = 
                insertX[theList, x, 
                  n]; 
  
theList = 
                insertY[theList, x, 
                  y]; 
  
n += 
                4; 
  
x += 
                4; 
  
];
Return[Partition[theList, 2]];
]

z = {{0, 0}, {70, 0}}

randomMidpoints[z, 20]

q = randomMidpoints[z, 20]

Clear[q]

repeatMidpoints[z_, q_] := 
      Module[{d, y}, 
y = 20; 
d = 
          randomMidpoints[z, y]; 
Do[
d = 
            randomMidpoints[d, 
              y]; 
  
y = 
            1/2  y; 
Print["Y is now ", 
            y];
, {q}]; 
  
Show[
          Graphics[Line[d]]];
]

repeatMidpoints[{{0, 0}, {70, 0}}, 4]

z = {{0, 0}, {70, 0}}

z = randomMidpoints[z]

z = randomMidpoints[z]

z