Mandelbrot set: Difference between revisions
Content deleted Content added
m →{{header|C++}}: teplate to template twice |
gnu octave (with matlab syntax hl) |
||
Line 108: | Line 108: | ||
} |
} |
||
</lang> |
</lang> |
||
=={{header|GNU Octave}}== |
|||
This code runs rather slowly and produce coloured Mandelbrot set by accident (output image [http://i43.tinypic.com/zlp252.jpg here]). |
|||
<lang matlab>#! /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 |
|||
if ( ic == maxiter ) |
|||
ms(x+1, y+1) = 1.0; |
|||
else |
|||
ms(x+1, y+1) = ic/maxiter; |
|||
endif |
|||
endfor |
|||
endfor |
|||
saveimage("mandel.ppm", round(ms .* 255).', "ppm");</lang> |