This week’s challenge is to find an elegant solution to generating elements in a spiral pattern. Consider the following diagram…
Your solution can be procedural or recursive, but in either case you will be dealing with a shrinking grid of possible locations for elements. The colours do not have to be in the result - they are only used to indicate the pattern.
Hint: Try defining variables for columns and rows so that the shape can change but the positioning and order remain the same.
Post your solutions in the form of links to jsfiddle, tinker or jsbin (in the comment section) and we’ll update this post with a link to a review post detailing solutions that we think tackle the problem in ways worthy of mention.
We hope to make it a weekly thing, so be on the lookout for more challenges to follow!
EDIT [2012/08/08]: We have posted the review post to for these submissions.