// IFS Fern based on Paul Bourke's C source. // http://www.mhri.edu.au/~pdb/fractals/fern/ // Ported, modified and commented by Anders Haglund. // andershaglund@hotmail.com // // Rendering time with n = 10000 (on a p2-266 64Mb and Pov-Ray for Windows 3.1) // Parsing: 32 seconds // Rendering: 3 seconds // // This scene is made for Pov-Ray 3.1. (it doesn't work in 3.0) // // The general form of the series are: // x = a x + b yn + c // (n+1) n // y = d x + e yn + f // (n+1) n // // The Fern is made by randomizing the (a,b,c,d,e,f) set between 4 diffrent // sets: // set1 set2 set3 set4 // a 0.0 0.2 -0.15 0.75 // b 0.0 -0.26 0.28 0.04 // c 0.0 0.23 0.26 -0.04 // d 0.16 0.22 0.24 0.85 // e 0.0 0.0 0.0 0.0 // f 0.0 1.6 0.44 1.6 // p 0.1 0.08 0.08 0.74 // (p is the probability for that set to occur) // // To do: // * True 3D. Anyone got the IFS sets for a 3D Fern? Please e-mail me. camera { location <0,0,-5> look_at <0,0,0> } light_source { <0,0,-5> color rgb <1,1,1> } #declare n = 10000;// Number of spheres // Box to map IFS in to, used for scaling the IFS #declare nx = 4; #declare ny = 4; #declare r1 = seed(0) ;// Random seed for IFS #declare sphereradius = 0.02; // Radius of spheres, should get // smaler when n get bigger. // Don't modify these: // For finding bounding box of IFS (used for scaling and centering) #declare xmin = 1000000; #declare xmax = -1000000; #declare ymin = xmin; #declare ymax = xmax; // The four sets for the IFS #declare sets = array[4][6] { {0 ,0 ,0 ,0.16 ,0 ,0}, {0.2 ,-0.26,0.23 ,0.22 ,0 ,1.6}, {-0.15,0.28 ,0.26 ,0.24 ,0 ,0.44}, {0.75 ,0.04 ,-0.04,0.85 ,0 ,1.6} } #declare spheres = array[n] // Array for storing the spheres union { // Start position (Doesn't matter because the IFS is centered anyway) #declare xlast = 0; #declare ylast = 0; #declare i = 0; #while (i < n) // Loop once for every sphere // Find wich set to use #declare r = rand(r1); #if (r < 0.1) #declare k = 0; #end #if (r >= 0.1 & r < 0.18) #declare k = 1; #end #if (r >= 0.18 & r < 0.26) #declare k = 2; #end #if (r >= 0.26) #declare k = 3; #end // Calculate new coordinate #declare px = sets[k][0]*xlast+sets[k][1]*ylast+sets[k][4]; #declare py = sets[k][2]*xlast+sets[k][3]*ylast+sets[k][5]; #declare spheres[i] = ; // Store sphere // Find max and min values for scaling and centering #if (px < xmin) #declare xmin = px; #end #if (px > xmax) #declare xmax = px; #end #if (py < ymin) #declare ymin = py; #end #if (py > ymax) #declare ymax = py; #end // Save coordinate for next loop #declare xlast = px; #declare ylast = py; #declare i = i+1; #end #declare s = min(nx/(xmax-xmin),ny/(ymax-ymin)); // Calculate scaling #declare i = 0; #while (i < n) // Loop through the spheres // Create the spheres sphere { ,sphereradius pigment { color rgb } } #declare i = i+1; #end translate <-(xmin+xmax)/2*s,-(ymin+ymax)/2*s,0> // Center IFS }