function write_ppm_binary(A)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Schreibt eine ppm-Datei im binary Format, die die Matrix visualisiert
% Eingabeparameter:    A    Zu visualisierende Matrix
%                           mit nichtnegativen Einträgen
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Bestimme NX, NY (Anzahl Pixel in x- bzw. y-Richtung)

[NY,NX] = size(A);

% Bestimme maxit (Maximaler Wert der Eintraege in A)

maxit = max(max(A));


% Erzeuge ppm-Datei

dateiname = sprintf('mandel_%d_%d_%d_binary.ppm', NX, NY, maxit);
fid = fopen(dateiname, 'wb');

% Lege Farbwerte fest

rot1   = floor(linspace(50,250,10)');
rot2 = floor(linspace(255,155,maxit-10)');
rot=[rot1; rot2];

gruen1 = floor(linspace(200,100,15)');
gruen2 = floor(linspace(100,0,maxit-15)');
gruen=[gruen1; gruen2];

blau1  = floor(linspace(50,100,3)');
blau2 = floor(linspace(150,250,maxit-3)');
blau = [blau1; blau2];

farbe=[0 0 0; rot gruen blau];


% Schreibe Kopfzeile der ppm-Datei

fprintf(fid, 'P6 \n %d %d \n 255\n ', NX, NY);

% Schreibe RGB-Farbwerte jedes Pixels

for k=1:NY
   for j=1:NX
       fwrite(fid, farbe(A(k,j)+1,:));
    end
end

% Schliesse die ppm-Datei

fclose(fid);

