Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Complex = Object
- re: real;
- im: real;
- constructor init(r: real; i: real);
- function add_complex(other: Complex): Complex;
- function mul_complex(other: Complex): Complex;
- function abs: real;
- end;
- constructor Complex.init(r: real; i: real);
- begin
- re := r;
- im := i;
- end;
- function Complex.add_complex(other: Complex): Complex;
- var
- t: Complex;
- begin
- t.init(re + other.re, im + other.im);
- add_complex := t;
- end;
- function Complex.mul_complex(other: Complex): Complex;
- var
- t: Complex;
- begin
- t.init(re * other.re - im * other.im, re * other.im + im * other.re);
- mul_complex := t;
- end;
- function Complex.abs: real;
- begin
- abs := sqrt(re * re + im * im);
- end;
- function mandelbrot_test(c: Complex): byte;
- var
- f: boolean;
- i: byte;
- n: Complex;
- begin
- i := 0;
- f := true;
- n.init(0, 0);
- while (i < 255) and f do
- begin
- if n.abs() > 2 then
- f := false
- else
- n := n.mul_complex(n).add_complex(c);
- i := i + 1;
- end;
- mandelbrot_test := i;
- end;
- procedure mandelbrot(x1, y1, x2, y2: real; rx, ry, g: byte);
- var
- i, j: integer;
- t: Complex;
- begin
- for i := 0 to ry do
- begin
- for j := 0 to rx do
- begin
- t.init(x1 + (x2 - x1) * j / rx, y1 + (y2 - y1) * i / ry);
- if mandelbrot_test(t) >= g then
- write('*')
- else
- write(' ');
- end;
- writeln;
- end;
- end;
- var
- t: Complex;
- begin
- mandelbrot(-2, -1, 1, 1, 80, 24, 255);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement