Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
factor[n_] := Reverse[Flatten[
Map[Table[#[[1]], {#[[2]]}] &, FactorInteger[n]]]]
On[Assert];
Assert[factor[24] == {3, 2, 2, 2}];
draw[origin_, frame_, delta_, {p_, rest___}, start_] := {
Circle[origin, frame],
With[{r = If[p == 1, 1, frame Sin[Pi/p]/(1 + Sin[Pi/p])]},
Table[
With[{t0 = delta + 2 Pi i/p},
With[{t = t0 + If[p == 2, Pi/2, 0]},
With[{center = origin + (frame - r) {Cos[t], Sin[t]}},
If[Length[{rest}] == 0,
Disk[center, r],
(*Text[start+i,center],*)
draw[center, r, t0 + If[First[{rest}] == 2, Pi/2, 0], {rest}, start + i Times @@ {rest}]]]]],
{i, 0, p - 1}]]}
graphicalFactor[n_] := {
draw[{0, 0}, 1, 0, factor[n], 1],
Text[n, {0, 0},
BaseStyle -> {
FontFamily -> "Palatino",
FontSize -> fontSize,
If[n < 3, White, Black]}]}
fontSize = 24;
Manipulate[
Graphics[Flatten[graphicalFactor[n]], PlotRange -> All],
{n, 1, 1024, 1}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment