# GENERATE FRACTALS WITH MAPLE IN FEW EASY STEPS # # 1- Load the routine IFS (below) # 2- Define PHI, a list of lists containing the IFS parameters, # with the following format (see examples below): # >PHI:=[[a1,b1,c1,d1,e1,f1], # [a2,b2,c2,d2,e2,f2], # ... # [an,bn,cn,dn,en,fn]]: # # 3- generate and plot data # >fractal:=IFS(PHI,1000): # generate 1000 points # >plot(fractal,style=POINT,symbol=POINT,scaling=`constrained`,axes=`none`); #=========================================== ITERATED FUNCTION SYSTEM IFS:=proc(PHI::list(list),n::posint) local R, k, phik, z, Zlist: #---------------------------- procedures R:=rand(1..nops(PHI)): phik:=(x,y,a,b,c,d,e,f)->[x*a+y*b+e,x*c+y*d+f]: Zlist:=array(1..n): #--------------------------- initialize z:=[0.0,0.0]: Zlist[1]:=z: #--------------------------- recursion for k from 2 to n do z:=phik(op(z),op(PHI[R()])): Zlist[k]:=z od: #--------------------------- output op(Zlist) end: #=========================================== EXAMPLES #---------------------------------- fractal tree r:=1/2: h:=evalf((1+r/sqrt(2))/(1-r^2)): theta:=evalf(Pi/4.0): ct:=evalf(r*cos(theta)): st:=evalf(r*sin(theta)): PHItree:=[[ct,st,-st,ct,0.0,1.0], [ct,-st,st,ct,0.0,1.0], [0.0,0.0,0.0,1/h,0.0,0.0]]: #---------------------------------- fern (equal probability) phi1:=[ 0.0, 0.0, 0.0, 0.16, 0.0, 0.0 ]: phi2:=[ 0.85, 0.04,-0.04, 0.85, 0.0, 1.6 ]: phi3:=[ 0.2, -0.26, 0.23, 0.22, 0.0, 0.8 ]: phi4:=[-0.15, 0.28, 0.26, 0.24, 0.0, 0.44]: PHIfern:=[phi1,phi2,phi3,phi4]: #---------------------------------- fern (unequal probability) PHIfern2:=[phi1,phi2$10,phi3,phi4]: # note the Maple construct: x$4 -> x,x,x,x # the map phi2 is repeated 10 times, so its probability # is 10 times that of the other maps.