Javascript implementation of chaos game