The Computer Language
Benchmarks Game

mandelbrot Pascal Free Pascal #3 program

source code

{ The Computer Language Benchmarks Game
  http://benchmarksgame.alioth.debian.org

  contributed by Ales Katona
  modified by Vincent Snijders
}

program mandelbrot;

var n: longint;
    TextBuf: array[0..$FFF] of byte;
    OutFile: PText;
    

procedure run;
var
  Cy, Step: double;
  x, y, bits,bit: Longint;
  function CalculatePoint(Cx, Cy: double): boolean; inline;
  const
    Limit = 4;
  var
    i: longint;
    Zr, Zi, Ti, Tr: Double;

  begin
    Zr := 0;  Zi := 0; Tr := 0; Ti := 0;
    for i := 1 to 50 do begin
      Zi := 2*Zr*Zi + Cy;
      Zr := Tr - Ti + Cx;
      Ti := Zi * Zi;
      Tr := Zr * Zr;
      if (Tr + Ti>=limit) then exit(true);
    end;

    CalculatePoint := false;
  end;

begin
  Step := 2/n;
  for y := 0 to n-1 do
  begin
    Cy := y * Step - 1;
    bits := 255;  bit := 128;
    for x := 0 to n-1 do
    begin
      if CalculatePoint(x * Step  - 1.5, Cy) then
        bits := bits xor bit;

      if bit > 1 then
        bit := bit shr 1
      else
      begin
        write(OutFile^, chr(bits));
        bits := 255;  bit := 128;
      end;
    end;
    if bit < 128 then write(OutFile^, chr(bits xor((bit shl 1)-1)));
  end;
end;

begin
  OutFile := @Output;
  SetTextBuf(OutFile^, TextBuf);

  Val(ParamStr(1), n);
  writeln(OutFile^, 'P4');
  writeln(OutFile^, n,' ',n);
  run;
end.
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
Free Pascal Compiler version 3.0.2 [2017/02/05] for x86_64


Fri, 03 Mar 2017 18:26:27 GMT

MAKE:
mv mandelbrot.fpascal-3.fpascal mandelbrot.fpascal-3.pas
/usr/local/src/fpc-3.0.2.x86_64-linux/bin/fpc -FuInclude/fpascal -XXs -O4 -Tlinux  -oFPASCAL_RUN mandelbrot.fpascal-3.pas
Free Pascal Compiler version 3.0.2 [2017/02/05] for x86_64
Copyright (c) 1993-2016 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling mandelbrot.fpascal-3.pas
Linking FPASCAL_RUN
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
70 lines compiled, 0.1 sec
mv FPASCAL_RUN mandelbrot.fpascal-3.fpascal_run
rm mandelbrot.fpascal-3.pas
0.10s to complete and log all make actions

COMMAND LINE:
./mandelbrot.fpascal-3.fpascal_run 16000

(BINARY) PROGRAM OUTPUT NOT SHOWN