Cantor Function

SequenceOf01[n_]:=IntegerDigits[Range[0,2^n-1],2,n]

Manipulate[Graphics[Table[d=2 SequenceOf01[p];{Swatch,Thickness[0.005],Line[Table[{{Sum[d[[i,j]]/3^j,{j,1,p}]+1/3^p,i/2^p},{Sum[d[[i+1,j]]/3^j,{j,1,p}],i/2^p}},{i,1,2^p-1,2}]]},{p,1,k}],PlotRange->{{0,1/b},{0,1/b}},Axes->True,ImageSize->{1000,1000},ImagePadding->25],
{{k,10,"iterations"},1,10,1,Appearance->"Labeled"},
{{b,1,"magnification"},1,10,Appearance->"Labeled"},SaveDefinitions->True,TrackedSymbols->Manipulate]

For[i=1,i<9,i++,Export[StringJoin["cant",TextString[i],".png"], Graphics[Table[d=2 SequenceOf01[p];{Swatch,Thickness[0.005],Line[Table[{{Sum[d[[i,j]]/3^j,{j,1,p}]+1/3^p,i/2^p},{Sum[d[[i+1,j]]/3^j,{j,1,p}],i/2^p}},{i,1,2^p-1,2}]]},{p,1,i}],PlotRange->{{0,1},{0,1}},Axes->True,ImageSize->{1000,1000},ImagePadding->25],ImageSize->1000,Background->None]]

SetDirectory[NotebookDirectory[]]

CAPTION

This Demonstration runs eight iterations of the Cantor function. You can zoom in close to the origin to see the fractal nature of the function.

DETAILS

Program segment borrowed from M. Trott's The Mathematica Guidebook for Graphics, New York: Springer-Verlag, 2004.

THIS NOTEBOOK IS THE SOURCE CODE FROM

"Cantor Function" from the Wolfram Demonstrations Project
 http://demonstrations.wolfram.com/CantorFunction/

Contributed by: Douglas Rivers

A full-function Wolfram Mathematica system (Version 6 or higher) is required to edit this notebook.
GET WOLFRAM MATHEMATICA »

© Wolfram Demonstrations Project & Contributors   |   Terms of Use   |   Make a new version of this Demonstration »