Iterated Function Systems

We iterate the system of equations

The trick is that the values of a, b, c, d, e, f are switched randomly at each iteration. In the case that we will consider here, there will be two possible sets of values, and at each step we will use the first set some fixed percent of the time, and use the other set the rest of the time. For example, suppose we have the two sets of values

abe
cdf
 0.320.28-1.16
-1.050.47-1.25
-0.57-0.10-1.27
-0.41 0.57 0.60

Let's say we'll use the first set of values 60 percent of the time and the other set 40 percent of the time. We'll start just with x0=0 and y0=0. We then pick a random number between 1 and 100. If it's between 1 and 60 then we'll use the first set, and otherwise use the second set. Suppose it turned out to be 49. Then we'd use the first and get x1=-1.15 and y1=1.25. Plot this point (x1,y1) We then choose another random number between 1 and 100 and do the same thing. Keep doing this for a really long time, plotting all the points, and the really strange picture below on the left will show up, called an attractor.

There's lots of information on the web about these sorts of things. Pretty often people use 3 or more sets of values. For example, the 3 sets of values given below generate the Sierpinski triangle (shown above on right).

abe
cdf
.5 0 0
 0.5 0
.5 0.5
 0.5 0
.5 0.25
 0.5.43

Now we'll do a really similar thing to what we did above, except we'll iterate the system

I haven't seen this anywhere else, but I'm sure someone else has thought to do this. The images tend to become more curved. For example, with the two sets of values given below, we get the following image.

-0.87-0.74 0.94
-0.72 0.34 1.01
-0.81 0.24-0.36
-0.58-1.25 1.04

There is a gallery of images made in this way here. Below is some Java code to generate images by iterating the sin/cos system given above. The applet randomly selects values of a,b,c,d,e, and f. Each time the page is reloaded, the applet draws a new image. There is a more interactive version here.

import java.util.Random;
import java.applet.Applet;
import java.awt.*;

public class Ifs extends Applet
  {
  public void paint (Graphics g)
    {
    double x,y,oldx,oldy,mag,xshift,yshift;
    double[] a=new double[6],
             b=new double[6];
    int p,sx,sy,i,r,xres,yres;
    Random rand = new Random();

    xres=640;
    yres=480;
    mag=200;
    xshift=0;
    yshift=0;

    for (i=0; i<6; i++)
      {
      a[i]=(rand.nextInt(260)-130)/100.0;
      b[i]=(rand.nextInt(260)-130)/100.0;
      }
    p=rand.nextInt(98)+1;

    for (i=0,oldx=oldy=0; i<100000; i++)
      {
      r = rand.nextInt(100);
      if (r<p)
        {
        x=a[0]*Math.sin(oldx)+a[1]*Math.cos(oldy)+a[2];
        y=a[3]*Math.sin(oldx)+a[4]*Math.cos(oldy)+a[5];
        }
      else
        {
        x=b[0]*Math.sin(oldx)+b[1]*Math.cos(oldy)+b[2];
        y=b[3]*Math.sin(oldx)+b[4]*Math.cos(oldy)+b[5];
        }
      sx=(int)((x-xshift)*mag+xres/2.0);
      sy=(int)(-(y-yshift)*mag*3.0/4.0+yres/2.0);
      g.drawLine(sx,sy,sx,sy);
      oldx=x;
      oldy=y;
      }
    }
  }