# Chaos game - square fractal

**C**haos game is a mathematical way to generate fractals. It has a simple algorithm, which (1) starts from a radom point with a polygon, then (2) randomly selects a vertice, (3) plots a new point midway between the starting point and the selected vertice. The ploted mid point then becomes the step (1) and reiterates the steps as many times as you like to generate a geometric figure. The example below in this blog uses a square as the polygon to generate a chaos game square fractal.

The chaos game sqaure fractal below has two animations (i.e., **spin** and **travel**) applied for viewing. You can also navigate or rotate in the 3D space for your preferred viewpoint.

Perhaps the most famous one is that if you start with a trianlge, you will get the Sierpiński triangle. The interesting thing is that you can start from any polygon (I have not tried concave polygons) such as regular or irregular, and you can move midway or other distance such as one third to generate different fractals. This Wikipedia page demonstrates some examples of chaos game fractals. Below is the Logo program you may want to try in VRMath2 Editor.

; Chaos game fractal ; Sqaure, different from previous vertex CS RESET ST TRANSFORM ; make a transform for later animation MAKE "obj OBJECT SETPARENT :obj RU 90 BK 0.5 WEST 0.5 PD MAKE "p0 POS FD 1 RT 90 MAKE "p1 POS FD 1 RT 90 MAKE "p2 POS FD 1 RT 90 MAKE "p3 POS FD 1 RT 90 PU SHOWALL POINT PD MAKE "p 0 REPEAT 3000 [ IF :p = 0 [ TOWARDS :p0 FD (DISTANCEBTW POS :p0)/2 ] IF :p = 1 [ TOWARDS :p1 FD (DISTANCEBTW POS :p1)/2 ] IF :p = 2 [ TOWARDS :p2 FD (DISTANCEBTW POS :p2)/2 ] IF :p = 3 [ TOWARDS :p3 FD (DISTANCEBTW POS :p3)/2 ] MAKE "q RANDOM 4 WHILE :p = :q [ MAKE "q RANDOM 4 ] MAKE "p :q ] PU HT SETPARENT "root SPIN :obj "lt 10 HOME BK 2 MAKE "path [] QUEUE "path POS FD 10 QUEUE "path POS BK 10 QUEUE "path POS TRAVEL :obj :path 25

Further, this chaos game rule can be applied to 3D. This page shows some fractals I presented in ATCM Conference in 2017. You can try these fractals in the VRMath2 Editor by openning the logo grograms in Example --> logo --> fractal folder.

What will you try for chaos game fractals? Pentagon? Cube? Please leave a message below to let me know any comments or what you have tried. :-)

- Andy's blog
- Login or register to post comments
- 143 reads

## Facebook Comments Box