1. (* Modification of Szabolcs' answer to http://stackoverflow.com/q/6631333/421225*)
  2.  
  3. Clear[cantor, pairs, drawCantor]
  4.  
  5. pairs[ch_] := pairs[ch] = Tuples[ch - 1, 2]
  6.  
  7. cantor[size_, n_Integer, num_: 3, ch_: {1, 3}][pt_] :=
  8. With[{s = size/num, ct = cantor[size/num, n - 1, num, ch]},
  9. Table[ct[pt + tup s + 0.], {tup, pairs[ch]}]]
  10. cantor[size_, 0, _ : 3, _ : {1, 3}][pt_] := Rectangle[pt, pt + {size, size}]
  11.  
  12. drawCantor[n_, num_: 3, ch_: {1, 3}] := Graphics[cantor[1, n, num, ch][{0, 0}]]
  13.  
  14.  
  15. Export["CantorDustAnim124.gif", Table[drawCantor[n, 4, {1, 2, 4}], {n, 1, 5}]]
  16. (* http://i.imgur.com/C6lVO.gif *)