Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The figure is

the figure

See the how-to video or a speeded-up GIF.

I believe it should be possible to draw this figure programmatically using some Random function, but I'm rather new to Mathematica, so I could really use some help here.

share|improve this question
This is related. – J. M. Mar 24 at 0:22
Fun question. I still can't get over people spend their free time trying to draw things like this. – Liam Mar 24 at 3:00
@William, they spend the time because it is, as you say, fun. – J. M. Mar 24 at 3:15
Those are art forms. Mathematica can make a stunning variety of them. Over the past year I have been using Mathematica to design geometric sculptures. Part of the process is looking for attractive 3D graphics which are made up of elements that I can put together in the real world. I recently saw an unanticipated Graphics3D result that I have been able to make in solid form. The result has energetic beauty. – Ralph Dratman Mar 29 at 21:04
up vote 75 down vote accepted

Here's a quick take on it:

spiralize[p_, d_:10, r_:4, f_:0.8, s_:1, t_:0.005]:=Module[{m,rr=r},
   m = Mean @ p[[1]];
            RotationTransform[rr++s \[Degree],m]],
    ]&, p, d]}

pts = RandomReal[{-1, 1}, {50, 2}];
polys = MeshPrimitives[VoronoiMesh[pts], 2];

Show[spiralize[#, 40, 5, 0.85] & /@ polys]

enter image description here

Play with the parameters:

pts = RandomReal[{-1, 1}, {10, 2}];
polys = MeshPrimitives[VoronoiMesh[pts], 2];
 Show[spiralize[#, d, r, f, s, t] & /@ polys], {{d, 10}, 1, 20, 
  1}, {{r, 5}, 1, 20}, {{f, 0.85}, 0, 1}, {{s, 1}, 0.1, 
  3}, {{t, 0.001}, 0, 0.01}]

enter image description here

share|improve this answer
wow really cool :) thank you! is there any parameter I can play with to get different results? – AccidentalFourierTransform Mar 23 at 22:44
Yes, try changing the scaling and rotating arguments in the function. – M.R. Mar 23 at 23:46
vvoronoi[pts_] := ListDensityPlot[Append[#, 0]&/@ pts, InterpolationOrder-> 0, 
                                                       Frame -> False]

pts = RandomReal[{0, 256}, {20, 2}];
cp = Cases[Normal@voronoi[pts],  Polygon[a_, ___] :> Polygon[a], ∞];
cp1 = cp /. Polygon[a___] :> a;
ms = Mean /@ cp1;

Graphics[{EdgeForm[Black], FaceForm[White], cp, 
         Line /@ Join @@@ (Transpose /@ (MapThread[
         Table[BSplineFunction[Join[Join[#1, #1][[i ;; i + 1]], #2]][t], 
               {i, 1, Length@#1}] &, {cp1, List /@ ms}, 1] /. 
                                                 a_[t] :> a /@ Range[0, 1, .03]))}]

Mathematica graphics

share|improve this answer
an arc length parametrization would be better – Dr. belisarius Mar 23 at 22:32
it looks really nice :) thank you! what parameters could I change to get different results? (such as more/less spirals) – AccidentalFourierTransform Mar 23 at 22:46
@AccidentalFourierTransform The 20 in pts = RandomReal[{0, 256}, {20, 2}]; is the number of spirals. The spacing is determined by Range[0, 1, .03],so you may try things like (Rescale[Sin[# ^(2)] & /@ Range[0.001, 1, .05]]) instead – Dr. belisarius Mar 23 at 22:52

Here is a slightly different way of going about it:

BlockRandom[SeedRandom[42, Method -> "Rule30CA"]; (* for reproducibility *)
            pts = RandomReal[{-1, 1}, {50, 2}]];

With[{h = 1/5 (* offset *), n = 30 (* iterations *)}, 
     Graphics[{FaceForm[], EdgeForm[AbsoluteThickness[1/5]], 
               NestList[# /. Polygon[p_] :> 
                        Polygon[Transpose[Partition[p, 2, 1, 1], {1, 3, 2}].
                                {1 - h, h}] &, 
                        MeshPrimitives[VoronoiMesh[pts], 2], n]}]]

whirls all around

This version incorporates Rahul's suggestion to randomize the rotation directions:

With[{h = 1/5 (* offset *), n = 30 (* iterations *)},

     BlockRandom[SeedRandom[42, Method -> "Rule30CA"]; (* for reproducibility *)

                 pts = RandomReal[{-1, 1}, {50, 2}];

     Graphics[{FaceForm[], EdgeForm[AbsoluteThickness[1/5]], 
               NestList[# /. Polygon[p_] :> 
                        Polygon[Transpose[Partition[p, 2, 1, 1], {1, 3, 2}].
                                {1 - h, h}] &,
                        Map[RandomChoice[{Identity, Reverse}][#] &,
                            MeshPrimitives[VoronoiMesh[pts], 2], {2}], n]}]]]

spinning here or there

share|improve this answer
Maybe it's just a matter of perception, but I like this the best. I think (could be wrong), that the other answers have the lines simply spiraling into the center of the mesh cell, whereas they ought to hit the boundary before turning and heading to the next edge. +1 – LLlAMnYP Mar 24 at 8:19
Very perceptive of you! :) That's why I used linear interpolation over each polygon edge instead of scaling + rotating; that other approach will inevitably have corners jutting out of the spiral for some irregular polygons. – J. M. Mar 24 at 8:22
I wonder if it would be possible to make the edges of the Voronoi mesh less visible. In the original image the polygon edges are barely noticeable because the lines on either side start have a very uniform density, whereas here those edges are quite pronounced. – Martin Büttner Mar 24 at 9:07
@Martin, the other thing contributing to that illusion is that the polygons were not all rotated in the same direction. That I think takes more work to do. – J. M. Mar 24 at 9:14
@J.M. Oh, I just noticed that this solution doesn't do that yet. Yeah, that definitely helps with the uniform density, but I think even when the direction on two adjacent polygons is the same, is looks a bit more homogeneous. I'm not entirely sure how to go about that though... I'll see if I come up with anything. – Martin Büttner Mar 24 at 9:18

After seeing your awesome contributions I really wanted to do it myself, and I'm pretty happy with the result:

enter image description here

It took me quite a bit of time because I'm very rusty when it comes to progamming. Also, the code is probably highly inefficient, so any suggestion will be very appreciated.

The main idea to genetare this is to first draw some random quadrilaterals:

a = .25;                     (*side length*)
c:=.15 RandomReal[{-1, 1}];  (*random shifting*)
d = .15;
n = 3;                       (*n+1 rectangles in the x direc.*)
m = 2;                       (*m+1 rectangles in the y direc.*)

s =  NestList[{#[[2]],#[[2]]+{a+c,0},#[[2]]+{a+c,a+c},#[[3]],#[[2]]} &,{{0,0},{a+c,0},{a+c,a+c},{0,a+c},{0,0}},n];
f[x_] := Module[{k=FoldList[{#1[[2]],#2[[3]],#2[[3]]+{c,a+c},#1[[3]],#1[[2]]}&,{#[[4]],#[[3]],#[[3]]+{c,a+c},#[[4]]+{c,a+c},#[[4]]}&[x[[1]]],Rest@x]},
q = NestList[f,s,m];
q = Partition[#,2]&/@Partition[Flatten[q],10];

enter image description here

The, I randomly turn some of these quadrilaterals into triangles:


enter image description here

And finally, I generate the spirals inside each polygon:


This approach has many flaws compared to the other answers but the most important one is that one has to execute the code many times to get a decent result (because most of the times the polygons overlap).

share|improve this answer
They are just quadrilaterals, not rectangles. :) (A rectangle is a parallelogram with a right angle.) – J. M. Apr 1 at 13:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.