Purpose: to generate Sierpinski's triangle with a seemingly chaotic algorithm. Uses drawing, random numbers, and a "For" loop on the TI-83.
This algorithm begins with an equilateral triangle. When performing the process on paper, a random point is chosen within the triangle as a starting point. Then a die is rolled (or some other method of randomization) choosing a vertex. The midpoint between the original random point and the random vertex is then plotted. Starting with the newly plotted point, the process is then repeated. We can plot this on paper several times, but after a while it becomes tedious. Writing a program to perform the procedure many times will save us from having to do it.
Because the program is used to graph a picture, we must set up the graph it will be plotted on. Turn functions off, clear any drawings, and turn the statistics plots off with the following commands: FnOff, ClrDraw, and PlotsOff. To make sure the X and Y axes do not interfere with our graph, also use the AxesOff command. All of these commands (along with any other) can be found in the Catalog by pressing the yellow 2nd followed by the zero key.
Now set the domain and range. The "VARS" key (3rd row, 4th column) contains menus of variables. The variables Xmax, Xmin, Ymax, Ymin are contained in the "Window..." menu.
Let Xmin=0 and Xmax=1.
Let Ymin=0 and Ymax=1.
Then a random number (between 0 and 1) is stored as the first x coordinate, likewise for the y.
Now comes the "For" loop. To obtain a good picture, command the program to loop (plot a new point) a large number of times--more than you would ever plot on paper. I choose 3000. Note: the more points you choose they longer the program will run. 3000 takes about 6 minutes to run.
How can we simulate the random selection of a vertex? Since the calculator function "rand" automatically chooses something between 0 and 1, divide those selections into thirds. That is, if the random number is less than 1/3, designate one vertex; if the random number is between 1/3 and 2/3, designate the second vertex; if the random number is greater than 2/3, designate the third vertex. How can we determine the half way point between the plotted point and the newly chosen vertex?
Think in terms of the range in your window. For the equilateral triangle to fit in this domain and range, what must the coordinates of the vertices be?
Obviously the vertices are the origin, (1,0) and (0.5,0.866). How can you determine the value of the y coordinate of point C?
"If" statements can be used to test the value of the random number N.
When random number N is less than or equal to 1/3, we will plot a new point half way between the orignal (X,Y) and vertex A (the origin). This is the easiest one to consider. The new point would be (0.5X, 0.5Y), so store those as new values of X and Y.
For random numbers greater than 1/3 and less than or equal to 2/3, choose vertex C. How can you calculate the midpoint of (X,Y) and vertex C?
Go ahead and write two more "If" statements for vertices B and C which store the midpoint as the new X and Y coordinates.
Now that our new X and Y values are stored, they can be plotted using the "Pt-On" command. It is found in the "Draw" menu under "Points." Access the "Draw" menu by pressing the yellow "2nd" button followed by the "PGRM" button, which we are all too familiar with.
The "For" loop can now "End." Store your new graph for good measure using the "Store Pic" command under the "DRAW" menu (right arrow over to "STO").
For the rest of my code, click here.
RETURN to Intro/Program List