Try now in the
Open Cloud »
(no sign-in required)

# Polygonal Mandalas

Make colorful mandala-like designs.

Run the code to draw a line through the 5 points of a pentagon (5-sided polygon). Try a different number of points:

CirclePoints gives points evenly spaced around a circle.

Draw the 5 corners of a pentagon (5-sided polygon):

 In[1]:= XGraphics[Point[CirclePoints[5]]]
 Out[1]=

Connect the points with a line:

 In[2]:= XGraphics[Line[CirclePoints[5]]]
 Out[2]=

The bottom of the pentagon is missing because the line is drawn from the first point to the last point, but not back to the first point again.

 In[1]:= XGraphics[Line[CirclePoints[5]]]
 Out[1]=

Draw a line joining each pair of points. Try a different number of points:

This gives a list of every pair of numbers (2-tuple) drawn from the list {1,2,3}:

 In[1]:= XTuples[{1, 2, 3}, 2]
 Out[1]=

This gives a list of every pair of points drawn from the list of three points evenly spaced around a circle:

 In[2]:= XTuples[CirclePoints[3], 2]
 Out[2]=

Map (/@) applies a function, like Line, to every element of a list.

Draw a line connecting each pair of points:

 In[3]:= XGraphics[Line /@ Tuples[CirclePoints[5], 2]]
 Out[3]=

 In[1]:= XGraphics[Line /@ Tuples[CirclePoints[5], 2]]
 Out[1]=

Show pictures for successively more points. Try starting and ending numbers other than 4 and 20:

Table makes lists of things.

This makes a list of numbers from 4 to 20 in steps of 1:

 In[1]:= XTable[n, {n, 4, 20, 1}]
 Out[1]=

This makes a list of figures with 4 to 20 points:

 In[2]:= XTable[Graphics[Line /@ Tuples[CirclePoints[n], 2]], {n, 4, 20, 1}]
 Out[2]=

 In[1]:= XTable[Graphics[Line /@ Tuples[CirclePoints[n], 2]], {n, 4, 20}]
 Out[1]=

Make it interactive. Drag the slider to change the number of points:

Replace Table with Manipulate to get a slider that you can control the number of points with:

 In[1]:= XManipulate[ Graphics[Line /@ Tuples[CirclePoints[n], 2]], {n, 4, 20, 1}]
 Out[1]=

 In[1]:= XManipulate[ Graphics[Line /@ Tuples[CirclePoints[n], 2]], {n, 4, 20, 1}]
 Out[1]=

Make it colorful:

Were going to need a few new concepts to make a colored line figure. Lets take it in small steps.

A pure function is a function that doesnt have a name.

This pure function (indicated by # and &) adds 1 to a number:

 In[1]:= X(# + 1) &[5]
 Out[1]=

Use the pure function with Map (/@) to add one to every number in a list:

 In[2]:= X(# + 1) & /@ {9, 3, 12}
 Out[2]=

An equivalent way to write the same thing is to use the function Map instead of the /@ shorthand:

 In[3]:= XMap[(# + 1) &, {9, 3, 12}]
 Out[3]=

MapIndexed is like Map. In fact, you get the same result if you use MapIndexed instead of Map:

 In[4]:= XMapIndexed[(# + 1) &, {9, 3, 12}]
 Out[4]=

But MapIndexed makes the list position of each element the function is applied to available to the function. Use #2 to get the position:

 In[5]:= XMapIndexed[{(# + 1), #2} &, {9, 3, 12}]
 Out[5]=

Use First to extract the position number from the list:

 In[6]:= XMapIndexed[{(# + 1), First[#2]} &, {9, 3, 12}]
 Out[6]=

Youll use the list position to specify the colors of lines in a line figure.

Hue gives different colors for different values between 0 and 1:

 In[7]:= XTable[Hue[h/10], {h, 0, 10, 1}]
 Out[7]=

You can use Hue to color objects in Graphics:

 In[8]:= XGraphics[{Hue[0.8], Line[{{0, 0}, {1, 1}}]}]
 Out[8]=

Now you have all the concepts you need to color the lines in a figure.

This is the basic figure with black lines:

 In[9]:= XGraphics[Map[Line, Tuples[CirclePoints[12], 2]]]
 Out[9]=

Use MapIndexed to color the lines according to their positions in the list. Dividing the Hue value by 12 gives 12 different colors of lines.

 In[10]:= XGraphics[MapIndexed[{Hue[First[#2]/12], Line[#]} &, Tuples[CirclePoints[12], 2]]]
 Out[10]=

Add color to the interactive figure:

 In[11]:= XManipulate[ Graphics[MapIndexed[{Hue[First[#2]/n], Line[#]} &, Tuples[CirclePoints[n], 2]]], {n, 4, 30, 1}]
 Out[11]=

 In[1]:= XManipulate[ Graphics[MapIndexed[{Hue[First[#2]/n], Line[#]} &, Tuples[CirclePoints[n], 2]]], {n, 4, 30, 1}]
 Out[1]=

Share ItMake a website with an interactive mandala:

Deploy the Manipulate to the Wolfram Cloud where anyone with a browser can use it:

 In[1]:= XCloudDeploy[ Manipulate[ Graphics[MapIndexed[{Hue[First[#2]/n], Line[#]} &, Tuples[CirclePoints[n], 2]]], {n, 4, 30, 1}], Permissions -> "Public" ]
 Out[1]=

Click the link in the output to visit the site.

Share the link by right-clicking it and choosing Copy Address. Paste the link into an email, tweet, or other message.

 In[1]:= XCloudDeploy[ Manipulate[ Graphics[MapIndexed[{Hue[First[#2]/n], Line[#]} &, Tuples[CirclePoints[n], 2]]], {n, 4, 30, 1}], Permissions -> "Public" ]
 Out[1]=