home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / FRACTAL.ZIP / FRACTAL.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1985-03-11  |  2.5 KB  |  77 lines

  1. program fractal(input,output);
  2.    {$I complex.pas}
  3.    {plot fractal curve by recursive evaluation of f-1(z) where
  4.                 f(z)=Lambda*z*(1-z)
  5.     Turbo Pascal Version of Sorensen article in Byte Mag. Sept. 1984
  6.              Requires Complex Function Library
  7.        J.M.Weiss, 1572 Peacock Ave., Sunnyvale, CA 94087
  8.                         3/6/85 }
  9.    var
  10.       Lambda,One,Two,Four:Complex;
  11.  
  12.    procedure fractal_func(z:Complex;VAR Result:Complex);
  13.       var
  14.          temp1,temp2,temp3,temp4,temp5:Complex;
  15.          temp6:Complex;
  16.          xx:Real;
  17.  
  18.       begin {fractal_func}
  19.          Cdiv(z,Lambda,temp1);
  20.          Cmult(Four,temp1,temp2);
  21.          Csub(One,temp2,temp6);
  22.          Csqrt(temp6,temp3);
  23.          xx:=Random;
  24.          if xx>0.5 then Csub(One,temp3,temp4)
  25.                        else Cadd(one,temp3,temp4);
  26.          Cdiv(temp4,Two,temp5);
  27.          Result:=temp5
  28.       end; {fractal_func}
  29.  
  30.       var
  31.          z,temp1,temp2,temp3:Complex;
  32.          Scale,x,y:Real;
  33.          i,ix,iy:Integer;
  34.       const
  35.          cx:Real=320.;
  36.          cy:Real=100.;
  37.          Initial:Integer=10;
  38.  
  39.       begin {main}
  40.  
  41.          Cmplx(1.0,0.0,One);
  42.          Cmplx(2.0,0.0,Two);
  43.          Cmplx(4.0,0.0,Four);
  44.       {initial value of z}
  45.          Cmplx(0.5,0.0,z);
  46.       {get parameters}
  47.          Writeln(' =============== FRACTAL GENERATOR ===============');
  48.          Writeln(' For samples, try complex Lambda = 3. 0.  Scale=1.');
  49.          Writeln('              or                   0. 1.        5.');
  50.          Writeln('              or                   1. 0.        5.');
  51.          Writeln(' Each display will terminate by pressing any key.');
  52.          Writeln(' Then explore.');
  53.          Writeln(' =================================================');
  54.          Writeln;
  55.          Writeln(' Enter Complex Value of Lambda: ');
  56.          Readln(Lambda.re,Lambda.im);
  57.          Writeln(' Enter Scale Factor: ');
  58.          Readln(Scale);  Scale:=2.*Cx/Scale;
  59.          ClrScr;
  60.          HiRes;
  61.          HiResColor(4);
  62.       {initialize calc. by 10 iterations}
  63.          for i:=1 to Initial do fractal_func(z,z);
  64.          repeat
  65.             i:=i+1;
  66.             x:=z.re;
  67.             y:=z.im;
  68.             x:=Scale*(x-0.5)+cx;
  69.             y:=cy-0.5*Scale*y;
  70.             ix:=Trunc(x);
  71.             iy:=Trunc(y);
  72.             if (ix <= 640) and (iy <= 320) then
  73.                Plot(ix,iy,1);
  74.             fractal_func(z,z);
  75.          until KeyPressed
  76.       end. {main}
  77.