You are on page 1of 1

SIERPINSKI

/*Defining 4 points*/

x[0] = 2; /* "x" coordinate for the seed */


y[0] = 0; /* "y" coordinate for the seed */
x[1] = 3; /* point 1 */
y[1] = 4;
x[2] = 5; /* point 2 */
y[2] = -3;
x[3] = -1; /* point 3 */
y[3] = 0;

/*for (i=0 ; i<4; i++) {


print x[i], "\t", y[i],"\n";
}
*/ /* Just to check points are correct */

/*Idea of rolling a die*/


/*Code for a random number "n" between 1 and 3*/
n = uniform (0,1);

tmax = 1000; /* It will give you the amount of iterations */

for(t = 0; t < tmax; t += 1)


{

/* Move the seed to the point midway between the current location and the point 1 */
if (n<=1/3) {xf = (x[0] + x[1])/2; yf = (y[0] + y[1])/2;}

/* Move the seed to the point midway between the current location and the point 2 */
if (n>1/3 && n<=2/3) {xf = (x[0] + x[2])/2; yf = (y[0] + y[2])/2;}

/* Move the seed to the point midway between the current location and the point 3 */
if (n>2/3 && n<=1) {xf = (x[0] + x[3])/2; yf = (y[0] + y[3])/2;}

/* Update seed point */


x[0] = xf;
y[0] = yf;

print x[0], "\t", y[0], "\n";

/* Code for a new random number "n" between 1 and 3 */


n = uniform (0,1);
/*print n, "\n";*/
}

quit

You might also like