RosettaCodeData/Task/Mandelbrot-set/Octave/mandelbrot-set.octave
Ingy döt Net d066446780 langs a-z
2013-04-10 22:43:41 -07:00

34 lines
690 B
Text

#! /usr/bin/octave -qf
global width = 200;
global height = 200;
maxiter = 100;
z0 = 0;
global cmax = 1 + i;
global cmin = -2 - i;
function cs = pscale(c)
global cmax;
global cmin;
global width;
global height;
persistent px = (real(cmax-cmin))/width;
persistent py = (imag(cmax-cmin))/height;
cs = real(cmin) + px*real(c) + i*(imag(cmin) + py*imag(c));
endfunction
ms = zeros(width, height);
for x = 0:width-1
for y = 0:height-1
z0 = 0;
c = pscale(x+y*i);
for ic = 1:maxiter
z1 = z0^2 + c;
if ( abs(z1) > 2 ) break; endif
z0 = z1;
endfor
ms(x+1, y+1) = ic/maxiter;
endfor
endfor
saveimage("mandel.ppm", round(ms .* 255).', "ppm");