(* The Mandelbrot set    *)

M=Compile[{x,y},Block[{z=x+I y,k=0},While[Abs[z]<2&&k<50,z=z^2+x+I y;++k];k]];
DensityPlot[50-M[x,y],{x,-2.,1.},{y,-1.5,1.5},PlotPoints->100,Mesh->False];

(* Julia sets            *)

J=Compile[{x,y,u,v},
  Module[{z=u+I v,k=0},While[Abs[z]<200.&&k<50,z=z^2+x+I y;++k];k]];
Julia[x_,y_]:=DensityPlot[50-J[x,y,u,v],{u,-1.,1.},{v,-1.,1.},
  PlotPoints->100,Mesh->False];

DouadyRabit:=Julia[-0.121,0.739];           Dragon:=Julia[0.36,0.1]
Gullik:=Julia[0.32,0.043];                  Dendrite:=Julia[0,1]
Airplane:=Julia[-1.754878,0.];              Cauliflower:=Julia[0.25,0.]
Dust1:=Julia[0.255,0]                       Dust2:=Julia[-0.75,0.1]

(* Barnsley's fern       *)

f={Function[x,{{ 0.000, 0.000}, { 0.000,0.270}}.x+{   .5  ,      0}],
   Function[x,{{-0.139, 0.263}, { 0.246,0.224}}.x+{   0.57, -0.036}],
   Function[x,{{ 0.170,-0.215}, { 0.222,0.176}}.x+{  0.408,  0.089}],
   Function[x,{{ 0.781, 0.034}, {-0.032,0.739}}.x+{ 0.1075,  0.270}]};
U:=Module[{u=Random[]},If[u<0.02,1,If[u<0.17,2,If[u<0.3,3,4]]]];
g[x_]:=f[[U]][x]; start=Last[NestList[g,{0,0},100]];
ListPlot[NestList[g,start,10000], Axes->False];

(* The Sirpinski carpet  *)

Sirp[0,{i1_,j1_}]:={Rectangle[{i1,j1}]};
Sirp[n_,{i2_,j2_}]:=Module[{s={}},Do[If[Not[u==v==2],
 s=Union[s,Sirp[n-1,{u*3^(n-1)+i2,v*3^(n-1)+j2}]]],{u,3},{v,3}];s];
Show[Graphics[Sirp[4,{0,0}]], AspectRatio->1];

(* The Menger Sponge     *)

<<Graphics`Polyhedra`
Menger[0,{i_,j_,k_}]:={Cuboid[{i,j,k}]};
Menger[n_,{i_,j_,k_}]:=Module[{s={}},Do[If[Not[u==v==2 || v==w==2 || u==w==2],
 s=Union[s,Menger[n-1,3^(n-1)*{u,v,w}+{i,j,k}]]],{u,3},{v,3},{w,3}];s];
Show[Graphics3D[Menger[2,{0,0,0}]],Boxed->False, Axes->False];

