46 lines
830 B
Text
46 lines
830 B
Text
max_iter = 50
|
|
width = 400; height = 401
|
|
scale = 10
|
|
xmin = -2; xmax = 1/2
|
|
ymin = -5/4; ymax = 5/4
|
|
|
|
define mandelbrot(c_re, c_im) {
|
|
auto i
|
|
|
|
# z = 0
|
|
z_re = 0; z_im = 0
|
|
z2_re = 0; z2_im = 0
|
|
|
|
for (i=0; i<max_iter; i++) {
|
|
# z *= z
|
|
z_im = 2*z_re*z_im
|
|
z_re = z2_re - z2_im
|
|
# z += c
|
|
z_re += c_re
|
|
z_im += c_im
|
|
# z2 = z.*z
|
|
z2_re = z_re*z_re
|
|
z2_im = z_im*z_im
|
|
if (z2_re + z2_im > 4) return i
|
|
}
|
|
return 0
|
|
}
|
|
|
|
print "P2\n", width, " ", height, "\n255\n"
|
|
|
|
for (i = 0; i < height; i++) {
|
|
y = ymin + (ymax - ymin) / height * i
|
|
for (j = 0; j < width; j++) {
|
|
x = xmin + (xmax - xmin) / width * j
|
|
tmp_scale = scale
|
|
scale = 0
|
|
m = (255 * mandelbrot(x, y) + max_iter + 1) / max_iter
|
|
print m
|
|
if ( j < width - 1 ) print " "
|
|
scale = tmp_scale
|
|
|
|
}
|
|
print "\n"
|
|
}
|
|
|
|
quit
|