Skip to content

Instantly share code, notes, and snippets.

@scruss
Created June 22, 2016 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scruss/0a81abf2da3eff85b547fc20e1666cdc to your computer and use it in GitHub Desktop.
Save scruss/0a81abf2da3eff85b547fc20e1666cdc to your computer and use it in GitHub Desktop.
a sample Fortran-77 program that produces a greyscale Mandelbrot set in PGM format to stdout
program mandlsm
*
*
*
implicit none
integer nx,ny,maxiter,ix,iy,mslsm,j
parameter (nx=512,ny=512,maxiter=256)
external mslsm
integer mset(nx,ny)
real cx,cy,xmin,xmax,ymin,ymax
parameter (xmin=-2.0,xmax=2.0,ymin=-2.0,ymax=2.0)
do iy=1,ny
cy=ymin+(real(iy)*(ymax-ymin)/real(ny))
do ix=1,nx
cx=xmin+(real(ix)*(xmax-xmin)/real(nx))
mset(ix,iy)=mslsm(cx,cy,maxiter)
end do
end do
* Now write as PGM file
write(*,fmt='(A2)')'P2'
write(*,*)nx,ny
write(*,*)maxiter-1
do iy=1,ny
do ix=0,(nx/16)-1
write(*,FMT='(16I4)')
$ (mset(j,iy),j=1+16*ix,(16*ix)+16)
end do
end do
end
*
integer function mslsm(qcx,qcy,m)
*
*
*
implicit none
real qcx,qcy,x,y,x2,y2,temp,huge
parameter (huge=10000.0)
integer iter,m
x=0.0
y=0.0
x2=0.0
y2=0.0
iter=0
do while ((iter.lt.m).and.((x2+y2).lt.huge))
temp=x2-y2+qcx
y=2*x*y+qcy
x=temp
x2=x**2
y2=y**2
iter=iter+1
end do
mslsm=iter
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment