Skip to content

Instantly share code, notes, and snippets.

@taroyabuki
Created February 20, 2015 15:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taroyabuki/50f24e2b0889ce67c3e7 to your computer and use it in GitHub Desktop.
Save taroyabuki/50f24e2b0889ce67c3e7 to your computer and use it in GitHub Desktop.
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