reeder@reed.UUCP (Doug Reeder) (04/06/89)
{This is my rendition of the IFS decoding program}
{ in the January 88 Byte, p221}
{It is followed by four data files for use with it.}
{Each data table should be in a file of its own.}
PROGRAM IFS (output);
CONST
MaxTransformations = 20;
xscale = 250;
yscale = 250;
xoffset = 5;
yoffset = 25;
VAR
IFSdata : text;
a, b, c, d, e, f, p : ARRAY[1..MaxTransformations] OF real;
pk, x, y : real;
n, k, h, v : integer;
PROCEDURE ReadData; {reads data from text file}
VAR
j, m : integer;
pk, pt : real;
filename : STRING;
BEGIN
filename := OldFilename('IFS data file ');
{This is a Lightspeed Pascal function. You will have to get the filename some other way}
reset(IFSdata, filename);
readln(IFSdata, m);{# transformations}
pt := 0;
FOR j := 1 TO m DO
BEGIN
readln(IFSdata, a[j], b[j], c[j], d[j], e[j], f[j], pk);
pt := pt + pk;
p[j] := pt;
END;
writeln(output, 'total probability ', pt);
p[m] := 1; {just to be sure}
END; {ReadData}
BEGIN {IFS}
ReadData;
x := 0;
y := 0;
{LS Pascal routines:}
{ SetDrawingRect(screenbits.bounds);}
{ ForeColor(GreenColor);}
{ ShowDrawing;}
FOR n := 1 TO 5000 DO
BEGIN
pk := (random + 32768) / 65536; {0 <= pk < 1}
k := 1;
WHILE pk > p[k] DO
k := k + 1;
x := a[k] * x + b[k] * y + e[k];
y := c[k] * x + d[k] * y + f[k];
IF n > 10 THEN
BEGIN
h := round(x * xscale) + xoffset;
v := round(y * yscale) + yoffset;
moveto(h, v);
lineto(h , v );
{you can replace moveto, lineto with a plot(h,v) or}
{writeln(h, v) to see the numbers}
END;
END;
END.
{here are the data tables}
{Each data table should be in a file of its own,}
4
0.85 0.04 -0.04 0.85 0 1.6 0.85
-0.15 0.28 0.26 0.24 0 0.44 0.07
0.2 -0.26 0.23 0.22 0 1.6 0.07
0 0 0 0.16 0 0 0.01
3
0.5 0 0 0.5 0 0 0.34
0.5 0 0 0.5 1 0 0.33
0.5 0 0 0.5 0.5 0.5 0.33
4
0.5 0 0 0.5 0 0 0.25
0.5 0 0 0.5 0.5 0 0.25
0.5 0 0 0.5 0 0.5 0.25
0.5 0 0 0.5 0.5 0.5 0.25
4
0.42 0.42 -0.42 0.42 0 0.2 0.4
0.42 -0.42 0.42 0.42 0 0.2 0.4
0.1 0 0 0.1 0 0.2 0.15
0 0 0 0.5 0 0 0.05
--
Doug Reeder USENET: ...!tektronix!reed!reeder
Institute of Knowledge BITNET: reeder@reed.BITNET
Jinx from ARPA: tektronix!reed!reeder@berkeley.EDU
reeder@knowledge.JINX Box 971 Reed College,Portland,OR 97202