||||||||||||||| ||||||||||||||| ||||||||||||||| ||||||||||||||| ||||||||||||||| || || Programming Assignment 1 || CSE 505 || Jason Secosky (jasons) || || Problem 4: || The following program can be used to generate points an infinite || number of points within an interated function system (IFS). || There are two IFS's implemented to generate the points for the || fractals Sierpinski Triangle and Fern. || || The idea is based on the article, "Recursive Images," by Steven || Janke in Dr. Dobbs Journal, July 1991, pp. 16-22. || || Interated Function Systems (IFS): || A detailed description of the algorithms used and IFS's are || described in detail in the above article. The following is a || short summary. || An IFS is a recursive function which means that the output || of a function becomes the input for the same function. In this case || the inputs and outputs are coordinate pairs (x,y). For the function || let the input point have the coordinates (X,Y) and the output || point the coordinates (Xnew, Ynew), then the functions are based on || the following relation: || || Xnew = a*X + b*Y + c || Ynew = d*X + e*Y + f || || The six numbers a,b,c,d,e,f describe the function. We can have || several functions which we use in our system with different || a,b,c,d,e,f values. Functions can be chosen based on probabilites, || to emphasize some transformations on the points and not others. || Another important aspect of the transforms is that they must || have some contraction, so that the distance between two successive || points becomes lower. If this is not true, the system to grow || infinitely large. So the transforms restrict the max range of values || that could be produced by the transforms. || || The points evaluated in the infinite list can redirected to a file, || formatted with sed, and plotted with gnuplot. The following || instructions show how to obtain graphical output. || || 1. Within Miranda execute: || (take 10000 fern) &> fern10k.fil || (take 10000 sierp) &> sierp10k.fil || || 2. Exit Miranda, when fern10k.fil and sierp10k.fil stop growing || (this can be checked by running ps aux | grep ) || || 3. Running sed: || Run sed with the following sed script. || || miraToGnuplot.sed: || s/[//g || s/]//g || s/)/ || /g || s/(//g || s/,/ /g || || sed -f miraToGnuplot.sed fern10k.fil > fernA10k.fil || sed -f miraToGnuplot.sed sierp10k.fil > sierpA10k.fil || NOTE: some versions of sed cannot handle the size of a line || which Miranda outputs. I have the most success using the || version of sed on a Sun computer. || || 4. Run gnuplot: || Type gnuplot at the unix prompt. Within gnuplot enter: || plot "fernA10k.fil" || plot "sierpA10k.fil" || You should now see the points plotted to a window on the || screen. || ||||||||||||||| ||||||||||||||| ||||||||||||||| ||||||||||||||| ||||||||||||||| || || random seed a c m || Generate a random number based on a seed value || || randoms seed a c m || Generate a list of random numbers based on a seed value || || This code was borrowed from J. Henikoff's code to generate lists of || random numbers. I am not sure of all the details, but it seems to || good random numbers for fern and sierpinski || random seed a c m = (seed*a + c ) mod m randoms seed a c m = [r | r <- random seed a c m, random r a c m..] || || recursiveImage t nt || Generic function to generate lists of points from the IFS. || t : the set of functions to use in the interated function system || nt : the range of values from 0..nt-1 that the random number || generator should generate. || || makeRI (x,y) (p:r) || Recurse to generate points of the IFS, will build the actual || list of points by applying t to (x,y) and then passing this || result as the (x,y) to makeRI to calculate another pt. || (i.e. makeRI (x,y) = (x,y) : makeRI (t (x,y)) <<= recursion on new pt) || || (x,y) : current point of IFS || (p:r) : p is the random number used to pick which transform in the || IFS we are going to use. r is the rest of the random number || list that is lazily evaluated. || recursiveImage t nt = makeRI (0,0) (map (mod nt) (randoms 5 259 0 (2^16))) where makeRI (x,y) (p:r) = (x,y) : makeRI (t (x,y) p) r || || t_sierp (x,y) n || t_fern (x,y) n || These are the actual IFS. The (x,y) value is the current point || being transformed and n is based on a random number or select || which one of the transforms of the IFS to use. || t_sierp (x,y) n = ( (0.5 * x), (0.5 * y) ), n = 0 = ( (0.5 * x) + 100, (0.5 * y) ), n = 1 = ( (0.5 * x) + 50, (0.5 * y) - 100 ), n = 2 t_fern (x,y) n = (0, (0.16 * y)), n <= 200 = ((0.2*x) - (0.26*y), (0.23*x) + (0.22*y) - 24), n <= 265 = (-(0.15*x) + (0.28*y), (0.26*x) + (0.24*y) - 6.6), n <= 330 = ((0.85*x) + (0.04*y), -(0.04*x) + (0.85*y) - 24), otherwise || || fern || sierp || Simplified calls to recursiveImage for fern and sierp || fern = recursiveImage t_fern 1001 sierp = recursiveImage t_sierp 3