Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating fractals

Status
Not open for further replies.

groom03

Technical User
Apr 27, 2010
1
GB
I've got to write a fortran program that will calculate fractals then graph them in excel.

i've got the iterative equation z=z^2+c. c is a complex constant throughout the equation. heres how i think my program should run.

the program picks a complex value for z and runs it through the iterative equation and if it diverges after a few iterations then the value is discarded and a new one chosen. if the value converges then it is stored and a new value for z is chosen. the problem is i have no clue how to get the program to pick randon values for z, i can do a loop that will store or chuck the value based on its divergence or convergence.

any and all help greatly appreciated, i'm fairly new at this sort of thing
 
Hi groom03

Maybe this can help you:

Code:
	program julia

	implicit none

	integer itermax,magnify,hxres,hyres
	real*8 breakout,cr,ci,x0,y0
	real*8 x,xx,y,xl,yl,zsq,zm,rb
	integer iter,hx,hy
	integer 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,'(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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top