//prog13.cpp //(c) 1997, Oguz Yetkin 12/2/1997 //yetkin@cs.wisc.edu //(the code for the graphics library is at //http://www.cs.wisc.edu/~yetkin/code // //Physics 505, Assignment 13 // //general purpose iterated function systems generator!!! // //the program comes with its own 2 built in fractals. You can //make your own, though. With no arguments, the program will //go into demo mode. If you want to use your own fractals, //cut and paste the following into a file called demo.ifs //and then type //prog13 demo.ifs // //cut here /* -3 3 -0 10 0 0 0 0.16 0 0 0.85 0.04 -0.04 0.85 0 1.6 0.2 -0.23 0.23 0.2 0 1.6 -0.15 0.28 0.26 0.24 0 0.4 */ //the first line is xmin xmax ymin ymax //(note xmin must be -xmax...an unfortunate bug I haven't gotten around //to fixing yet). // //the next 4 lines each contain 6 values and specify f1,f2,f3, and f4 //needed to generate the fractal. You can change these values...the given //values generate Barnsley's Fern #include #include #include //for int random(int) #include #include #include #include "graph.h" #define MAX_ITERS 50000 const int MAX_FERN=40000; const int DISCARD=200; //to store ifs values const int POLYNOMIAL_SIZE=6; //a,b,c,d,e,f const int NUM_SIERPINSKI_FUNCS=3; const int NUM_FERN_FUNCS=4; const int MAX_FUNCS=4; const int MAX=100; //constant POLYNOMIAL_SIZE must exist void plotxy(float* p, float &x, float &y); float frand(); //returns a random number between 0 and 1 int main(int argc, char** argv){ //the ifs function is stored in a dynamically allocated //2-D array of MAX_FUNCS rows and POLYNOMIAL_SIZE columns float** ifs1; //for the sierpinski triangle float** ifs2; //for the fern float** ifs3; //general purpose int i=0; //good old 'i' int current=0; //current function float x,y,xnew,ynew; char ch; char filename[MAX]; ifstream infile; int dummy; float xmin,xmax,ymin,ymax; //to be read from file //ifstream infile; //allocate memory ifs1=new float*[NUM_SIERPINSKI_FUNCS]; //3 for(i=0;i1){ infile.open(argv[1]); if(!infile){ cout<<"\nfile error!!!"; exit(1); } infile>>xmin>>xmax>>ymin>>ymax; graphsetup(xmin,xmax,ymin,ymax); //F1 //distort whatever is in ifs3 pretty badly //(these could be "weights" or just 1's and 0's //all 1's will result in random values between 1 and 0) //assume file is in correct format //xmin xmax ymin ymax //followed by 4 rows by 6 columns infile>>ifs3[0][0]; infile>>ifs3[0][1]; infile>>ifs3[0][2]; infile>>ifs3[0][3]; infile>>ifs3[0][4]; infile>>ifs3[0][5]; //F2 infile>>ifs3[1][0]; infile>>ifs3[1][1]; infile>>ifs3[1][2]; infile>>ifs3[1][3]; infile>>ifs3[1][4]; infile>>ifs3[1][5]; //F3 infile>>ifs3[2][0]; infile>>ifs3[2][1]; infile>>ifs3[2][2]; infile>>ifs3[2][3]; infile>>ifs3[2][4]; infile>>ifs3[2][5]; //F4 infile>>ifs3[3][0]; infile>>ifs3[3][1]; infile>>ifs3[3][2]; infile>>ifs3[3][3]; infile>>ifs3[3][4]; infile>>ifs3[3][5]; for(i=0;i