The Cantor set

Manipulate[With[{horizontalRange=Which[c-E^r<0,{0,Min[2 (E^r),1]},c+E^r>1,{Max[1-2 (E^r),0],1},True,{c-E^r,c+E^r}]},Graphics[{Blue,Antialiasing->True,Rectangle@@{{#[[1]],0},{#[[2]],1}}&[#]&/@Select[Nest[Flatten[({{#1[[1]],#1[[1]]+(1/3) (#1[[2]]-#1[[1]])},{#1[[2]]-(1/3) (#1[[2]]-#1[[1]]),#1[[2]]}}&)/@#1,1]&,{{0,1}},n],Last@Union[{#[[1]]<horizontalRange[[2]],#[[2]]>horizontalRange[[1]]}]&]},
PlotRange->{horizontalRange,{0,1}},
AspectRatio->Full, ImageSize->{600,150},LabelStyle->20,Axes->If[a,{True,False},None],Ticks->If[a,{Join[Nest[#[[1;;-1;;2]]&,Flatten[Nest[Flatten[({{#1[[1]],#1[[1]]+(1/3) (#1[[2]]-#1[[1]])},{#1[[2]]-(1/3) (#1[[2]]-#1[[1]]),#1[[2]]}}&)/@#1,1]&,{{0,1}},n]],If[#<0,0,#]&[Round[1/Log[((Subtract@@Reverse@horizontalRange)/11)/(3^-n),3]]]],{{c,Invisible[1/6]}}],Automatic},None]]],
{{n,1,"number of iterations"},0,9,1,ImageSize->Large,Appearance->"Labeled"},
{{c,N[8/27],"pan along axis"},0,1,ImageSize->Large,Appearance->"Labeled"},
{{r,-2/3,"zoom"},-2/3,-10,ImageSize->Large},
{{a,True,"show number line"},{True,False}},ControlPlacement->Bottom,AutorunSequencing->{{1,10},{2,5},{3,5}}]

Credit: Eric Rowland

Creation of this notebook was supported by IT Academy program of Information Technology Foundation for Education (HITSA).