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

# Moiré Patterns

Overlay grids of points and see patterns emerge.

Run the code to make an array of points. Try increasing the size from 3:

This draws a grid of 9 points:

 In[1]:= XGraphics[{ {Point[{-1, -1}], Point[{-1, 0}], Point[{-1, 1}]}, {Point[{0, -1}], Point[{0, 0}], Point[{0, 1}]}, {Point[{1, -1}], Point[{1, 0}], Point[{1, 1}]} }]
 Out[1]=

An easier way to make a grid of points is with Table.

This makes a grid of points where x and y vary from -1 to 1 in steps of 1:

 In[2]:= XTable[Point[{x, y}], {x, -1, 1}, {y, -1, 1}]
 Out[2]=

This draws the grid:

 In[3]:= XGraphics[Table[Point[{x, y}], {x, -1, 1}, {y, -1, 1}]]
 Out[3]=

Put more points in the grid by changing 1 to 3:

 In[4]:= XGraphics[ Table[Point[{x, y}], {x, -3, 3}, {y, -3, 3}]]
 Out[4]=

 In[1]:= XGraphics[Table[Point[{x, y}], {x, -3, 3}, {y, -3, 3}]]
 Out[1]=

Change the size of the grid with a slider:

Make anything interactive with Manipulate.

To make the grid interactive, replace the 3s with the variable n, wrap the Graphics expression with Manipulate, and specify that n varies from 3 to 10 in steps of 1. Now you can change the size of the grid by dragging the slider:

 In[1]:= XManipulate[ Graphics[Table[Point[{x, y}], {x, -n, n}, {y, -n, n}]], {n, 3, 10, 1} ]
 Out[1]=

 In[1]:= XManipulate[ Graphics[Table[Point[{x, y}], {x, -n, n}, {y, -n, n}]], {n, 3, 10, 1} ]
 Out[1]=

Include a second grid, rotated by 30 degrees. Try rotating by different amountsfor example, 45 degrees:

Use With to give the table of points the name points (this will make the next steps easier):

 In[1]:= XWith[{points = Table[Point[{x, y}], {x, -10, 10}, {y, -10, 10}]}, Graphics[points] ]
 Out[1]=

Rotate the points by 30 degrees:

 In[2]:= XWith[{points = Table[Point[{x, y}], {x, -10, 10}, {y, -10, 10}]}, Graphics[Rotate[points, 30 Degree]] ]
 Out[2]=

Draw the unrotated and rotated points together:

 In[3]:= XWith[{points = Table[Point[{x, y}], {x, -10, 10}, {y, -10, 10}]}, Graphics[{points, Rotate[points, 30 Degree]}] ]
 Out[3]=

 In[1]:= XWith[{points = Table[Point[{x, y}], {x, -10, 10}, {y, -10, 10}]}, Graphics[{points, Rotate[points, 30 Degree]}] ]
 Out[1]=

Allow the angle to be varied interactively:

This gives two interactive grids rotated 30 degrees from each other:

 In[1]:= XManipulate[ With[{points = Table[Point[{x, y}], {x, -n, n}, {y, -n, n}]}, Graphics[{points, Rotate[points, 30 Degree]}] ], {n, 3, 10, 1} ]
 Out[1]=

Add an angle control by replacing 30 with the variable angle and specifying that the angle varies from 0 to 180:

 In[2]:= XManipulate[ With[{points = Table[Point[{x, y}], {x, -n, n}, {y, -n, n}]}, Graphics[{points, Rotate[points, angle Degree]}] ], {n, 3, 10, 1}, {angle, 0, 180} ]
 Out[2]=

 In[1]:= XManipulate[ With[{points = Table[Point[{x, y}], {x, -n, n}, {y, -n, n}]}, Graphics[{points, Rotate[points, angle Degree]}] ], {n, 3, 10, 1}, {angle, 0, 180} ]
 Out[1]=

Share ItMake an interactive website for exploring moiré patterns:

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

 In[1]:= XCloudDeploy[ Manipulate[ With[{points = Table[Point[{x, y}], {x, -n, n}, {y, -n, n}]}, Graphics[{points, Rotate[points, angle Degree]}] ], {n, 3, 10, 1}, {angle, 0, 180} ], 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[ With[{points = Table[Point[{x, y}], {x, -n, n}, {y, -n, n}]}, Graphics[{points, Rotate[points, angle Degree]}] ], {n, 3, 10, 1}, {angle, 0, 180} ], Permissions -> "Public" ]
 Out[1]=