enter image description here

Draw a series of connected polygons like the one shown above.

However, what the above picture does not show is the spiral formed by consecutive vertexes:

enter image description here

The limitation of these is that there is only 1 spiral marked. You should mark all the spirals. This can be done by rotating each spiral shown above so that there is a spiral starting at each vertex of the largest polygon.

The spirals should all be one color, while the rest of the picture another.

The innermost polygon should be entirely the color of the spiral.


  • You will receive the arguments { n, s, p, a } in a function or program
  • n = iterations inward (number of polygons)
  • s = sides of the (regular) polygon (you may assume n>=3)
  • p = (the linear distance from a vertex of polygon A to its corresponding counter-clockwise "inner" vertex) / (the total length of A's side). So for the diagram, p would be about 1/3 because each inner polygon meets the larger polygon's side at about 1/3 of the way through that side.
  • a = the radius (circumscribing) of the exterior polygon

The limit of any of the values of n,s,p or a are based on what can be perceived as this kind of drawing by a human. (e.g. no shaded circles) as well as common sense (s>=3,n>=1)

Happy golfing! Shortest program wins.

  • 1
    \$\begingroup\$ Is the parameter p linear in angle or in distance between two vertices? \$\endgroup\$ Commented Oct 2, 2014 at 6:05
  • \$\begingroup\$ Sorry for the confusion, hopefully the edits will clear things up. \$\endgroup\$ Commented Oct 2, 2014 at 11:16
  • \$\begingroup\$ You should color it a different color than the other lines. So each side will have 2 colors - one that goes p through it, and the rest a different color. \$\endgroup\$ Commented Oct 2, 2014 at 11:21
  • \$\begingroup\$ @MartinBüttner I think he means that all the spirals (the clockwise portion of all sides) should be a highlight colour (like red) and the rest of the side should be the basic foreground colour (like black.) This would give s anticlockwise red spirals. However, what remains would be s clockwise black spirals! StretchManiac, this is a good question but we really need an example picture to see what you mean. Upvoting and closevoting. \$\endgroup\$ Commented Oct 2, 2014 at 17:00
  • \$\begingroup\$ Openvoting, though it would be helpful to confirm if the innermost polygon should be filled (I understand it shouldn't.) \$\endgroup\$ Commented Oct 3, 2014 at 8:42

1 Answer 1


Mathematica, 218 206 bytes


Expects the input as an array as defined in the question, e.g. {20, 7, 0.5, 100}:

enter image description here

or {20, 5, 0.333, 100}

enter image description here

These images still use red and grey from an earlier version, but the new version uses black for the counter-clockwise spirals and red for the rest.

I've included an axis, because otherwise the a parameter is meaningless with a vector graphic. I've also interpreted p as a linear interpolation in position, not in angle.


{n, s, p, a} = Input[];
t = 0;
    c = Array[a {Cos[u = t + 2 Pi #/s], Sin@u} &, s + 1];
    m = (f = p #2 + (1 - p) # &) @@ c;
    a = Norm@m;
    t = ArcTan @@ m;
    k = #;
    {Line@{#, x = f@##}, If[k < n, Red], Line@{x, #2}} & @@@ 
     Thread@{c, RotateLeft@c}
    ) &~Array~n
 Axes -> 1 > 0]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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