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 - JAMBO hopper */
 
#include <jambo.h>
 
#define LIMITE  50000
 
Main
  ancho = 700, alto = 150
  x=0,y=0,color=0
  vertice=0, 
  c=0, Let( c := Utf8(Chr(219)))
  Let(x := Int(Rand(ancho)))
  Let(y := Int(Rand(alto)))
 
  mid ancho=0, Let( mid ancho:= Div(ancho,2))
 
  i=LIMITE
  Void(pixeles)
  Loop
      Ceil(Rand(3)), Move to (vertice)
      If( Eq(vertice,1) )
          Let(x := Div(x, 2))
          Let(y := Div(y, 2))
          color=9
      Else If( Eq(vertice,2))
          Let(x := Add( mid ancho, Div(Sub(mid ancho, x), 2) ) )
          Let(y := Sub( alto, Div( Sub(alto, y), 2 )))
          color=10
      Else
          Let(x := Sub(ancho,  Div( Sub(ancho, x), 2)))
          Let(y := Div(y, 2))
          color=4
      End If
      Set( Int(y), Int(x), color),Apndrow(pixeles)
      --i
  Back if (i) is not zero
 
  Set video graph(2)
  Canvas-term  
  Cls
  i=1
  Iterator(++i, Leq(i,LIMITE), Colorfore([i,3]Get(pixeles)), \
                               Locate( [i,1]Get(pixeles), [i,2]Get(pixeles) ), Print(c) ); Prnl
  Pause
  Set video text
End
 