Wolfram Research

Function Repository Resource:

ChaosGame

Source Notebook

Plot iterations for the 2D chaos game

Contributed by: Eric Weisstein

ResourceFunction["ChaosGame"][n,iter,drop]

gives iter iterations of the chaos game on an n-gon with iter points using a ratio of 1/2, dropping the first drop points. ResourceFunction["ChaosGame"][{n,r},iter,drop] uses a ratio r.

Details and Options

ChaosGame works only in 2D.

Examples

Basic Examples

Get three iterations:

In[1]:=
ResourceFunction["ChaosGame"][{5, 1/3}, 3, 0]
Out[1]=

Try several geometries:

In[2]:=
Show[GraphicsGrid[
  Partition[(Graphics[{PointSize[.005], Point /@ ResourceFunction["ChaosGame"][#1, 2000]}] &) /@ {{3, 1/2}, {5, 1/3}, {5, 3/8}, {6, 1/3}}, 2]]]
Out[2]=

With more more iterations:

In[3]:=
GraphicsGrid[
 Partition[
  Table[Graphics[{PointSize[.005], Point /@ ResourceFunction["ChaosGame"][i, 30000]}], {i, 3, 6}], 2]]
Out[3]=

Increase ratios:

In[4]:=
GraphicsGrid[
 Partition[
  Graphics[{PointSize[.005], Point /@ ResourceFunction["ChaosGame"][{4, #}, 2000]}, AspectRatio -> Automatic] & /@ {0.25, 0.4, 0.5, 0.6, 0.75, 0.9}, 3]]
Out[4]=

An animation of the process:

In[5]:=
ChaosGameAnimation[{n_Integer?Positive, r_}, pts_: 10] := Module[{nf},
  Graphics[{
      {PointSize[.02], Red, Point[Through[{Cos, Sin}[Pi/2 + 2 Pi #/n]] & /@ Range[0, n - 1]]},
      MapIndexed[Text[#2[[1]], .03 {1, 1} + #1] &, #], Point[#]}] & /@
    Reverse[
    NestList[Most, ResourceFunction["ChaosGame"][{n, r}, pts, 0], pts]]
  ]
In[6]:=
ListAnimate[ChaosGameAnimation[{5, 1/3}, 10]]
Out[6]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

License Information