'FRACTAL MOUNTAIN GENERATOR 'This program generates fractal mountains in QBasic. For more detail, read the 'section "How to make a fractal mountain." CLS SCREEN 12 RANDOMIZE TIMER DIM points(4000, 2) DIM newpoint(4000, 2) DIM tempoints(4000, 2) columns = 2 points(1, 1) = 10 'The way we have created the 'points' array is: points(1, 2) = 440 'The first dimension refers to which 'column' the point points(2, 1) = 310 'is in. The 'columns' are the lines of points from the points(2, 2) = 240 'upper left edge of the triangle, travelling down and points(3, 1) = 610 'to the right, ending at the bottom edge. points(3, 2) = 440 'The second dimension refers to which horizontal row the times = 300 'point is in. minus = 8 mult = -1 take = 100 FOR lop = 1 TO 6 'the range here tells the computer how many times 'the triangles are subdivided. 6 is my recommended 'number. times = times / 2 CLS num1 = 1 newpoints = 0 FOR col = 1 TO columns num1 = num1 + col - 1 'The part below generates new points. FOR num = 1 TO col - 1 newpoints = newpoints + 1 newpoint(newpoints, 1) = (points(num1 - 1 + num, 1) + points(num1 + num, 1)) / 2 newpoint(newpoints, 2) = (points(num1 - 1 + num, 2) + points(num1 + num, 2)) / 2 + (RND * times - minus) * mult 'LINE (newpoint(newpoints, 1), newpoint(newpoints, 2))-STEP(0, 0), 5 'LINE (points(num1 - 1 + num, 1), points(num1 - 1 + num, 2))-(points(num1 + num, 1), points(num1 + num, 2)) NEXT num FOR num = 1 TO col IF col <> columns THEN newpoints = newpoints + 1 newpoint(newpoints, 1) = (points(num1 - 1 + num, 1) + points(num1 - 1 + num + col, 1)) / 2 newpoint(newpoints, 2) = (points(num1 - 1 + num, 2) + points(num1 - 1 + num + col, 2)) / 2 + (RND * times - minus) * mult newpoints = newpoints + 1 newpoint(newpoints, 1) = (points(num1 - 1 + num, 1) + points(num1 + num + col, 1)) / 2 newpoint(newpoints, 2) = (points(num1 - 1 + num, 2) + points(num1 + num + col, 2)) / 2 + (RND * times - minus) * mult END IF NEXT num NEXT col 'the lines below merge the new points with the old points. new = 0 temp = 0 num1 = 1 columns = columns * 2 - 1 FOR col = 1 TO columns IF INT(col / 2) * 2 <> col THEN num1 = num1 + ((col + 1) / 2) - 1 temp = temp + 1 tempoints(temp, 1) = points(num1, 1) tempoints(temp, 2) = points(num1, 2) FOR num = 2 TO (col + 1) / 2 temp = temp + 1 new = new + 1 tempoints(temp, 1) = newpoint(new, 1) tempoints(temp, 2) = newpoint(new, 2) temp = temp + 1 tempoints(temp, 1) = points(num1 + num - 1, 1) tempoints(temp, 2) = points(num1 + num - 1, 2) NEXT num ELSE FOR num = 1 TO col temp = temp + 1 new = new + 1 tempoints(temp, 1) = newpoint(new, 1) tempoints(temp, 2) = newpoint(new, 2) NEXT num END IF NEXT col FOR i = 1 TO temp points(i, 1) = tempoints(i, 1) points(i, 2) = tempoints(i, 2) NEXT i 'drawit: num1 = 1 FOR col = 1 TO columns num1 = num1 + col - 1 'finally, the points are drawn FOR num = 1 TO col IF col <> columns THEN LINE (points(num1 + num - 1, 1), points(num1 + num - 1, 2) - take)-(points(num1 + col + num - 1, 1), points(num1 + col + num - 1, 2) - take) LINE (points(num1 + num - 1, 1), points(num1 + num - 1, 2) - take)-(points(num1 + col + num, 1), points(num1 + col + num, 2) - take) END IF IF num <> col THEN LINE (points(num1 + num - 1, 1), points(num1 + num - 1, 2) - take)-(points(num1 + num, 1), points(num1 + num, 2) - take) NEXT num NEXT col NEXT lop 'the computer then returns to near the top of the program to 'subdivide the traingles. END