Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!

# Recursive Cantor Dust

By: simonjtyler on Jul 11th, 2011  |  syntax: None  |  size: 0.60 KB  |  views: 62  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
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 *)
clone this paste RAW Paste Data
Top