macintosh_cookbook/examples/julia.pas
2020-05-08 21:02:19 +09:00

71 lines
1.1 KiB
ObjectPascal

program ExampleJulia;
const
scale = 0.01;
R = 10;
type
complex = record
r: Real;
i: real
end;
var
i, j, k, n, row, col, Nit: Integer;
x, y: Real;
z, znew, c: complex;
done, gone: Boolean;
drawingRect: Rect;
procedure prod (a, b: complex; var c: complex);
begin
c.r := a.r * b.r - a.i * b.i;
c.i := a.r * b.i + a.i * b.r;
end;
procedure add (a, b: complex; var c: complex);
begin
c.r := a.r + b.r;
c.i := a.i + b.i;
end;
procedure plot (c, r: integer);
begin
Moveto(c, r);
Lineto(c, r);
end;
begin
ShowText;
Writeln('Value of Nit,Cr,Ci?');
ReadLn(Nit, c.r, c.i);
Showdrawing;
SetRect(drawingRect, 200, 40, 600, 400);
SetDrawingRect(drawingRect);
ForeColor(blackColor);
n := 0;
for col := 1 to 400 do
for row := 1 to 400 do
begin
z.r := (col - 200) * scale;
z.i := (row - 200) * scale;
repeat
prod(z, z, znew);
add(znew, c, z);
gone := (z.r * z.r + z.i * z.i > R);
n := n + 1;
done := (n > Nit);
until done or gone or button;
if done then
plot(col, row);
n := 0;
end;
end.
{ note: Interesting fractals }
{ 10 0 1 }
{ 50 0.3 -0.5 }