I found this picture on the net.
How can I reproduce it in Mathematica?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI found this picture on the net.
How can I reproduce it in Mathematica?
I appreciate that attempts should be the minimum standard. As this does not resemble the desired result, perhaps it can be a starting point. I look forward to OP attempt and other answers.
f[n_, d_] := Module[{r = Range@n, a},
a = Sqrt[#]/d & /@ r;
MapThread[#1 {-Cos[#2], -Sin[#2]} &, {Sqrt[r], a}]]
di[n_, d_, rad_] := Module[{fu, pt, grad, pg},
fu = f[n, d];
pt = MapIndexed[{White, EdgeForm[Black], Disk[#1, rad],
Text[Style[Sqrt[ToString[First@#2]], Black], #1]} &, fu];
grad = Reverse[{{0, 0}, ##} & @@@ Partition[fu, 2, 1]];
pg = MapIndexed[{Hue[First@#2/n], EdgeForm[Black], Polygon@#1} &,
grad];
Graphics[Join[pg, pt]]
]
After some play:
di[87, 0.4, 0.5]
I tried to do this without looking at the previous answers... let me know if I accidentally plagiarized!
With[{n = 87},
Module[{radii = Sqrt[Range[n]], angles, coords},
angles = Accumulate @ Most[ArcCot[radii]] ~Prepend~ 0;
coords = radii * Transpose @ Through[{Cos, Sin}[angles]];
Graphics[{
EdgeForm[Black],
Reverse @ MapIndexed[{
FaceForm @ Blend[{White, RGBColor[.6, .7, 0], RGBColor[0, .2, 0]}, First@#2/n],
Polygon[#1 ~Append~ {0, 0}]
} &, Partition[coords, 2, 1]
],
FaceForm[White],
MapIndexed[{
Disk[#1, 1/3],
Text[Sqrt[ToString @ First[#2]], #1]
} &, coords
]
}, ImageSize -> Full]
]
]
I only spent about 15 minutes on this, but I think that this and the original have the correct angles, and that ubpdqn's is wrong...
P.S. I got my colors from:
Graphics3D[{RGBColor @@ #, Point@#} & /@
First /@ Take[
SortBy[Tally[
Join @@ ImageData[
Import["https://i.stack.imgur.com/jYcLD.png"]]], Last], -100]]
Series[Integrate[ArcCot[Sqrt[m]], {m, 0, n}, Assumptions -> n > 1], {n, \[Infinity], 0}]
. The angle is about equal to $2\sqrt{n}$, so di[_, 0.5, 0.5]
is pretty close to the original.
$\endgroup$
Apr 25, 2015 at 14:25
A mild refactoring of ubpdqn's code:
f[n_, d_] := #*Map[{-Cos[#], -Sin[#]} &, #/d] & @ Sqrt @ Range @ n
di[n_, d_, rad_] :=
Module[{fu, pt, grad, pg},
fu = f[n, d];
pt = MapIndexed[{Disk[#, rad], Sqrt[HoldForm @@ #2] ~Style~ Black ~Text~ #} &, fu];
grad = Reverse[{{0, 0}, ##} & @@@ Partition[fu, 2, 1]];
pg = MapIndexed[{Hue[#2/n], Polygon @ #} &, grad];
Graphics[{EdgeForm[Black], pg, White, pt}]
]
di[87, 0.4, 0.5]
I nest the right turns with # + Normalize@Cross[#] &
. Since 2012rcampion has rather solved the coloring, here's a version using a close match from one of Mathematica's gradients.
cf = Lighter[ColorData["AvocadoColors", 1. - #], (1. - #)^8] &;
With[{npts = 87},
Graphics[
GraphicsComplex[
NestList[# + Normalize@Cross[#] &, {1., 0.}, npts - 1] ~Append~ {0., 0.},
{EdgeForm[Thin],
Table[{cf[i/npts], Polygon[{i, i + 1, npts + 1}]}, {i, npts - 1, 1, -1}],
Table[{White, Disk[i, 1/3], Black, Text[HoldForm[Sqrt[#]] &@i, i]}, {i, npts}]}
],
BaseStyle -> {FontSize -> Scaled[0.1/Sqrt[npts]]}
]
]
Cross
is very clever, and GraphicsComplex
is a nice touch to keep it clean.
$\endgroup$
Apr 25, 2015 at 22:41