Algorithms   

Midpoint Method

The Midpoint Method can be used to create some fractals, but it is most commonly used for the Sierpinski Triangle. The method is based on randomly picking a point inside the triangle. At the next step, you choose a vertex at random and find the midpoint between that vertex and the current point. In the second step, you choose another vertex at random and do the same. If you repeat this a large number of times, you will get a pretty accurate picture of the Sierpinski Triangle. The following algorithm can be used to generate the Sierpinski Triangle.

Constants used:

number_of_points: each one takes some time, but the more the better
number_of_iterations: the more the better, but takes a lot longer
number_of_colors: number of colors available in the computer language you’re using

‘ repeat the algorithm for every point in the fractal
FOR num = 1 TO number_of_points
             ‘ choose coordinates of the initial point
             x = RND * 0.5
             y = RND * 0.5 * SQR(3)
             IF y > SQR(3) * x THEN
                          x = x + 0.5
                          y = SQR(3) * 0.5 - y
             END IF
             ‘ apply the midpoint iteration
             FOR c = 1 to number_of_iterations
                          ‘ choose a vertex at random
                          vertex = FIX(RND * 3)
                          SELECT CASE vertex
                                       ‘ lower-left vertex
                                       CASE 0:
                                                x = x / 2
                                                y = y / 2
                                       ‘ upper vertex
                                       CASE 1:
                                                x = (x + 0.5) / 2
                                                y = (y + SQR(3) / 2) / 2
                                       ‘ lower-right vertex
                                       CASE 2:
                                                x = (x + 1) / 2
                                                y = y / 2
                          END SELECT
             NEXT c
             ‘ plot the point with random coloring
             PSET (x, y), FIX(RND * number_of_colors)
NEXT num

forward

forward