Справочник функций

### Ваш аккаунт

Войти через:
Информацию о новых материалах можно получать и без регистрации:

### Почтовая рассылка

Подписчиков: -1
Последний выпуск: 19.06.2015

# How to create the IFS Fern

Written by Paul Bourke

 One of the very common and attractive forms generated by Iterated Function Systems (IFS) is the fern leaf shown on the right. The following will describe how to generate this form and allow the reader to experiment with other IFS generators. Iterated function systems are described by repeatedly computing terms in two series, one series describes the x coordinate and the other series the y coordinate. The equations describe translation, scaling, rotation, and shearing of points in a plane with the restriction that the transformations are "affine". The general form of the series are as follows xn+1 = a xn + b yn + c  yn+1 = d xn + e yn + f A point is drawn at each pair (xi,yi) for i greater than some number, typically 10 to 100. The magic is in finding the values of (a,b,c,d,e,f) that give the desired form. In many application it is necessary to have a number of sets of (a,b,c,d,e,f). As the series is being generated a particular set is chosen at random for each term. Such IFS systems are often known as Random Iterated Function Systems. The fern can be constructed using the table of value on the right.

It turns out that if the different sets of (a,b,c,d,e,f) are chosen with appropriate probabilities then the fern will "emerge" much faster and evenly than if the sets are chosen with equal chance. The last row in the table gives the optimal probabilities.

The fern above resulted from 100 thousand (105) iterations, that is, 100 thousand points are drawn (of course when drawn on the bitmap many will overlap)

 - set1 set2 set3 set4 a 0.0 0.2 -0.15 0.75 b 0.0 -0.26 0.28 0.04 c 0.0 0.23 0.26 -0.04 d 0.16 0.22 0.24 0.85 e 0.0 0.0 0.0 0.0 f 0.0 1.6 0.44 1.6 p 0.1 0.08 0.08 0.74

The image is self similar at all scales, one can zoom in as far as one wishes and the fronds will continue to resolve themselves. For example, the following image is a zoom in by 50. Note however that it takes an ever increasing number of iterations to resolve the image as the zoom factor increases, this image took 100 million (108) iterations.

# C Source

Some straightforward C source is given below which generates the figure shown above. Note, you will have to supply your own image drawing tools.

```#include "stdio.h"
#include "stdlib.h"
#include "math.h"
#include "paulslib.h"
#include "bitmaplib.h"

#define NX 1000
#define NY 1000

double a = {0.0,0.2,-0.15,0.75};
double b = {0.0,-0.26,0.28,0.04};
double c = {0.0,0.23,0.26,-0.04};
double d = {0.16,0.22,0.24,0.85};
double e = {0.0,0.0,0.0,0.0};
double f = {0.0,1.6,0.44,1.6};

int main(int argc,char **argv)
{
int i,j,k;
int n = 1000;
int ix,iy;
double r,x,y,xlast=0,ylast=0;
double xmin=1e32,xmax=-1e32,ymin=1e32,ymax=-1e32,scale,xmid,ymid;
BITMAP *image;
BITMAP white = {255,255,255};
BITMAP black = {0,0,0};

if (argc  xmax) xmax = x;
if (y > ymax) ymax = y;
if (j == 1) {
scale = MIN(NX / (xmax - xmin),NY / (ymax - ymin));
xmid = (xmin + xmax) / 2;
ymid = (ymin + ymax) / 2;
ix = NX / 2 + (x - xmid) * scale;
iy = NY / 2 + (y - ymid) * scale;
DrawPixel(image,NX,NY,ix,iy,black);
}
}
}

WriteBitmap(stdout,image,NX,NY,2);
}
```

# References

Demko, S., Hodges, L., and Naylor B
Construction of Fractal Objects with Iterated Function Systems
Computer Graphics 19, 3, July 1985, Pages 271-278

Barnsley, M.
Fractals Everywhere

Barnsley, F., and Sloan, A.D.
A Better Way to Compress Images
Byte Magazine, January 1988, Pages 215-222

Oppenheimer, P.E.
Real Time Design and Animation of Fractal Plants and Trees
Computer Graphics, 20, 4, 1986

Reghbati, H.K.
An Overview of Data Compression Techniques
Computer, 14, 4, 1981, Pages 71-76

Previous | Next | Index