I wish everybody on this forum a Merry Christmas and a Happy and Fortran-filled New Year 2010.
Below is a short F77 program that makes a nice Julia-Fractal picture, that Fortran beginners can play with during Christmas (change magnify=10 for instance). Compile and link the program, run it and open the resulting PPM picture ...
Below is a short F77 program that makes a nice Julia-Fractal picture, that Fortran beginners can play with during Christmas (change magnify=10 for instance). Compile and link the program, run it and open the resulting PPM picture ...
Code:
program julia
implicit none
integer itermax,magnify,hxres,hyres
real*8 breakout,cr,ci,x0,y0,x,xx,y,xl,yl,zsq,zm,rb
integer iter,hx,hy,red,green,blue
character*256 str
hxres = 500 ! horizontal resolution
hyres = 500 ! vertical resolution
itermax = 100 ! maximum iters to do
breakout = 64. ! |z|^2 greater than this is a breakout
magnify = 10 ! 10 is standard magnification
cr = -.7492 ! real part of c in z^2=z^2+c
ci = .1000 ! imaginary part of c in z^2=z^2+c
x0 = 0.09950 ! center of picture
y0 = -.00062 ! center of picture
open(unit=20,file='julia.ppm',status='unknown',form='binary')
write(20) 'P6',char(10)
write(str,'(a)') '# Created by Julia.for by gullipe'
write(20) str(1:32),char(10)
write(str,'(2(a,i6))') '# Magnify=',magnify,' Itermax=',itermax
write(20) str(1:32),char(10)
write(str,'(i3,1x,i3,a)') hyres,hxres,char(10)
write(20) str(1:8)
write(20) '255',char(10)
rb = sqrt(breakout)
do hy=1,hyres
do hx=1,hxres
y = 4*((hyres+1-hy-.5)/hyres-0.5)/magnify+y0
x = 4*((hx-.5)/hxres-0.5)/magnify+x0
zm = 0
do iter=1,itermax-1
xl = x
yl = y
xx = x*x-y*y+cr
y = 2.0*x*y+ci
x = xx
zsq = x*x+y*y
if (zsq.gt.zm) zm=zsq
if (zsq.gt.breakout) exit
enddo
if (iter.ge.itermax) then
red = 0
green = 255.*zm/breakout
blue = 255.*zm/breakout
else
red = 255*(rb+xl)/(2*rb)
green = 0
blue = .5*255*(rb+yl)/(2*rb)
endif
write(20) char(red),char(green),char(blue)
enddo
enddo
close(unit=20)
end