The Chaos Game is a method of generating the attractor of an iterated function system (IFS).

One of the best-known and simplest examples creates a fractal, using a polygon and an initial point selected at random.



Task
Play the Chaos Game using the corners of an equilateral triangle as the reference points.   Add a starting point at random (preferably inside the triangle).   Then add the next point halfway between the starting point and one of the reference points.   This reference point is chosen at random.

After a sufficient number of iterations, the image of a Sierpinski Triangle should emerge.



See also
 The Game of Chaos


 
' Chaos game
Const ancho = 320, alto = 240
Dim As Integer x, y, iteracion, vertice
x = Int(Rnd * ancho)
y = Int(Rnd * alto)
 
Screenres ancho, alto, 8
Cls
 
For iteracion = 1 To 30000
	vertice = Int(Rnd * 3) + 1
	Select Case vertice
    Case 1
        x = x / 2
        y = y / 2
        vertice = 4 'red
    Case 2
        x = (ancho/2) + ((ancho/2)-x) / 2
        y = alto - (alto-y) / 2
        vertice = 2 'green
    Case 3
        x = ancho - (ancho-x) / 2
        y = y / 2
        vertice = 1 'blue
    End Select
	Pset (x,y),vertice
Next iteracion
Sleep
End
 