[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

145.0. "2D Fractal Program" by NOVA::RAVAN () Tue Sep 11 1984 18:13

The following is a short FORTRAN program to create 2D fractals on
a VT125 or VT240.  The comments at the beginning of the program
explain it.  The algorithm came from a good article on fractals for
novices like me that appeared in BYTE magazine, September, 1984.

-Jim Ravan

	program fractal

C	Author: Jim Ravan (second-hand)

C	Converted from the original AppleSoft BASIC version
C	of the 2D fractal algorithm by Greg Turk which appeared
C	in the article 'FRACTALS', Byte, September 1984.

C	This program computes and displays 2D fractals
C	based on the complex equation:

C	f(x) = lambda * x * (1-x)

C	This program works on both VT125 and VT240 terminals.

C	This program is 'numerically brittle', that is, it has
C	no built-in error handling for underflow, overflow, or
C	output conversion errors.  This becomes obvious if, for
C	example, a 'bad' choice of lambda is made.  Unfortunately,
C	I don't know enough about fractals to be able to predict
C	the limits of a 'good' choice for lambda.

	real*4 cx,cy,lr,li,scale
	complex*8 lambda,x
	integer*4 i,ipoints,j,iplot,iclear
	character*80 summary

	integer*4 nseed1,nseed2
	character*1 esc,cc,cclear

	common nseed1,nseed2,esc,cc

C	Seed for RAN is generated from the time-of-day.

	nseed1 = mod(secnds(0.0),65536.) - 32767
	nseed2 = nseed1 * nseed1

C	Initial default parameter values.

	cx = 150.0
	cy = 240.0
	lr = 1.0
	li = 0.0
	scale = 100.0
	ipoints = 1000
	iclear = 1

C	Clear screen to begin.

	cc = '$'
	esc = char(27)
	call clear

C	Initial reminder.

	call lib$erase_line(24,1)
	call lib$put_line(
	1'ctrl-z to any prompt stops the program.',0)

C	Get parameters.

10	cx = getval('left hand x',cx)
	cy = getval('y axis',cy)
	lr = getval('lambda real',lr)
	li = getval('lambda imaginary',li)
	scale = getval('scale factor',scale)
	ipoints = igetval('number of points',ipoints)
	iclear = igetyn('clear the screen?',iclear)

D	iplot = igetyn('plot?',1)
D	if (iplot .eq. 2) then
D	    cc = ' '
D	    esc = char(32)
D	endif

	cclear = 'y'
	if (iclear .eq. 2) cclear = 'n'
	write (summary,20) cx,cy,lr,li,scale,ipoints,cclear
20	format('cx:',F6.2,', cy:',F6.2,
	1', lr:',F6.2,', li:',F6.2,
	2', scale:',F6.2,
	3', pnts:',I6,
	4', clr: ',A1)
	call lib$erase_line(24,1)
	call lib$put_line(summary,0)

	goto (30,10),igetyn('Continue? (no = reprompt)',1)

30	call lib$erase_line(1,1)
	call lib$erase_line(24,1)

C	Compute 4/lambda.

	lambda = cmplx (lr,li)
	lambda = 4.0 / lambda

C	Initial x value.

	x = (.5001, 0.0)

C	Clear the screen, if necessary.

	if (iclear .eq. 1) call clear

C	f(x) gets done 10 times here, but I'm not sure why...

	do 100 i = 1,10
	call f(x,lambda)
100	continue

C	main loop. do all the points.

	do 200 j = 1,ipoints

	call plot(x,cx,cy,scale)

	call f(x,lambda)

200	continue

C	Ask to do another.

	goto (10,999),igetyn('Another?',1)

999	call lib$erase_line(1,1)
	call lib$erase_line(24,1)
	call exit
	end

	real function getval(prompt,defval)

	character*(*) prompt
	character*80 response
	integer*4 type

	type = 1
	goto 5

	entry igetval(prompt,idefval)

	type = 2

5	if (type .eq. 1) then
	    write (response,10) prompt,defval
	else
	    write (response,11) prompt,idefval
	endif
10	format(A,' [',F6.2,'] = ')
11	format(A,' [',I10,'] = ')
	call lib$erase_line(1,1)
	call lib$put_line(response,0)
	call lib$set_cursor(1,itrim(response)+2)
	read (5,15,end=999) n,response
15	format (Q,A80)

C	If there is no response, supply the default value.

	if (n .eq. 0) then
	    if (type .eq. 1) then
		getval = defval
	    else
		igetval = idefval
	    endif

C	If there is a response, provide a trailing decimal point, if necessary,
C	then convert the response to a floating point number, or properly
C	convert the integer, if this is a call to igetval.

	else
	    if (type .eq. 1) then
		if (lib$locc('.',response) .eq. 0) then
		    response(n+1:n+1) = '.'
		endif
		read (response,20) getval
20	        format(F10.5)
	    else
		read (response,21) igetval
21	        format(I<n>)
	    endif
	endif

	return

999	call lib$erase_line(1,1)
	call lib$erase_line(24,1)
	call exit
	end

	integer function igetyn(prompt,idefault)

	character*(*) prompt
	character*80 answer
	character*6 yes,no,which
	data yes/'[yes]:'/,no/'[no]: '/

2	if (idefault .eq. 1) then
	    which = yes
	else
	    which = no
	endif
	write (answer,5) prompt,which
5	format(A,' ',A)
	call lib$erase_line(1,1)
	call lib$put_line(answer,0)
	call lib$set_cursor(1,itrim(answer)+2)
	read (5,9005,end=8999) i,answer
	if (i.eq.0) goto 7
	if (answer(1:1).eq.'y'.or.answer(1:1).eq.'Y') goto 20
	if (answer(1:1).eq.'n'.or.answer(1:1).eq.'N') goto 10
	goto 2

C	Provide the default answer.

7	igetyn = idefault
	goto 30

C	The explicit answer is 'NO'

10	igetyn = 2
	goto 30

C	The explicit answer is 'YES'

20	igetyn = 1
30	return

8999	call lib$erase_line(1,1)
	call lib$erase_line(24,1)
	call exit

C Format statements

9005	format (Q,A)

	end

	integer function itrim(string)
	character*(*) string

C This function returns the length of the input string with
C trailing ' ' characters removed.
C If the string contains only ' ' characters, 1 will be returned.

	do 10 i = 1,len(string)
	j = len(string) - i + 1
	if (string(j:j) .ne. ' ') goto 20
10	continue

20	itrim = j
	return
	end

	subroutine f(x,lambda)

	complex*8 x,lambda
	integer*4 nseed1,nseed2
	character*1 esc,cc

	common nseed1,nseed2,esc,cc

C	function of complex x: f(x) = lambda * x * (1 - x)

	x = x * lambda

D	write (6,10) 'After squaring',real(x),aimag(x)
D10	format(' ',A,' real x = ',F10.5,', imag x = ',F10.5)

	x = 1.0 - x

C	square root of complex x

	x = sqrt(x)

D	write (6,10) 'After square root',real(x),aimag(x)

	if (ran(nseed1,nseed2) .gt. .5) x = -x

200	x = 1.0 - x
	x = x / 2.0

D	write (6,10) 'After 1-x and halving',real(x),aimag(x)

	return
	end

	subroutine clear

	integer*4 nseed1,nseed2
	character*1 esc,cc

	common nseed1,nseed2,esc,cc

	write (6,10) cc,esc,esc,esc,esc
10	format(A1,A1,'[H',A1,'[2J',A1,
	1'P1pS(M0(L0)(AL0))S(I0)S(E)S[0,0]',A1,'\')

	return
	end

	subroutine plot(x,cx,cy,scale)

	complex*8 x
	integer*4 px,py,nseed1,nseed2
	character*1 esc,cc

	common nseed1,nseed2,esc,cc

	px = (scale * real(x)) + cx
	py = (scale * aimag(x)) + cy

	write (6,10) cc,esc,px,py,esc,esc
10	format(A1,A1,'PpP[',I3,',',I3,']V[]',A1,'\',A1,'[H')

	return
	end
T.RTitleUserPersonal
Name
DateLines
145.1AURORA::HALLYBTue Sep 11 1984 18:354
One interesting figure comes out when lambda real = 1.66 and imaginary = 1.11,
and scale factor = 400 (other values default).  Kinda like siamese dragons.

						John
145.2ADVAX::J_ROTHWed Sep 12 1984 01:2541
I also played with 2-D fractals immediately after seeing that article...

If anyone has a PC350 running P/OS they ought to try my program; it
directly accesses the bitmap so must be orders of magnitude faster
than communicating via a comm line using REGIS.

I did a fair amount of playing around with the fractals and discovered
a number of things.

There are two basic starting points, from which the recurrance
Z(N+1) = LAMBDA*Z(N)*(1-Z(N)) loops... one is Z=0 and the other is
(LAMBDA-1)/LAMBDA.

The point Z=0 has a predecessor of Z=1. Plugging it in and solving the
quadratic gives a pair of roots - each of those has a pair of distinct
predecessors, and so on.  Exploring the resulting tree gives an estimate
of the outline of the fractal.  Always choosing one of the roots
(say the one with the positive sign) seems to always converge to a stable
set of points.  Thus I assume that always choosing one of the roots in some
pattern would converge to a stable set of points as well. I think this
convergence is what allows you to get an outline of the fractal by exploring
backwards as these programs do.

I wrote a pair of programs - one chose one of the roots at random and the
other explicitly searches the resulting tree to successivly greater
depths.

The task images are in ADVAX::USER1:[JROTH.BITMAP] FRACTR.TSK (random)
and FRACTL.TSK (tree exploration).  The souces are there as well.

There are a few other high speed graphics goodies for the PC350 there as well.
A few LIFE demos, a multi-color, multi-lobed cardioid demo (dig up a machine
with a color monitor for that one), a snowflake curve program, and a rotating
tesseract (four dimensional cube) program.

They all do direct access to the bitmap, since I've found it to be far far
faster than using GIDIS or core graphics.

Have fun -

	Jim
145.3ADVAX::J_ROTHWed Sep 12 1984 02:1715
A comment about Jim Ravan's program...  since the points on any fractal
it produces are skew symmetric about the point (.5,0.) one should take
this into account by subtracting .5 before plotting to keep the pattern
centered. Also, you might as well plot both roots each time and then
choose one at random to proceed from.  Also, its better to start from
the point (1.,0.) instead of recursing backwards 10 times from the point
(.5,0.) since the point (1.,0.) is guaranteed to be on the curve... no
need to converge to it.

I changed the program slightly for this - its in the [jroth.bitmap]
directory.  The speed is not bad.  Good starting values of lambda are
in the neighborhood of magnitude .5 to 3 at any angle. Its interesting
to sweep lambda over a range and see how the curve crinkles up.

- Jim
145.4HARE::STANWed Sep 12 1984 19:0724
Here are some technical references:

Benoit B. Mandelbrot, Self-Inverse Fractals Osculated by Sigma-Discs and the
	Limit Sets of Inversion Groups, The Mathematical Intelligencer.
	5(1983) no. 2, pp. 9-17.

Benoit B. Mandelbrot, The Fractal Geometry of Nature. W. H. Freeman.
	San Francisco: 1982.

Anthony Barcellos, The Fractal Geometry of Mandelbrot. The College
	Mathematics Journal. 15(1984)98-114.

Martin Gardner, Mathematical Games. Scientific American.
	Dec. 1976 and also April 1978.

William J. Gilbert, Geometry of Radix Representations. in The Geometric Vein,
	edited by Davis, Grunbaum and Sherk. Springer-Verlag. New York: 1981.
	pp. 129-139.

William J. Gilbert. The fractal dimension of snoflake spirals. Notices of the
	American Mathematical Society. 25(1978) A-641.

Chandler Davis and Donald Knuth, Number Representations and dragon curves,
	I, II. Journal of Recreational Mathematics. 3(1970) 66-81, 133-149.
145.5TURTLE::GILBERTWed Sep 12 1984 21:3719
Actually, there are (many) other "cycles" from Z   = L Z (1 - Z );
in fact, an infinite number of them.		n+1	n      n

				  L - 1
Z  = Z	has roots R  = 0, or R  = ----- (as noted).
 1    0		   0	      1	    L
					  2
			  L + 1 +/- sqrt(L  - 2 L - 3)
Z  = Z	has roots R ,R  = ----------------------------, R  and R  (as above).
 2    0	           2  3		    2 L			 0	1

Z  = Z  has roots R , and R  (as above), and four other roots.
 3    0		   0       1

Z  = Z  has roots R , R , R , and R  (as above), and four other roots.
 4    0		   0   1   2	   3

				  2
Setting L to one of the roots of L  - 2 L - 3 = 0 produces an interesting curve.
145.6HARE::STANSun Sep 16 1984 18:3575
Newsgroups: net.math
Path: decwrl!decvax!mcnc!unc!ulysses!mhuxl!houxm!houxf!vax135!petsd!cjh
Subject: Fractals: recent articles
Posted: Thu Sep 13 16:24:42 1984

	Fractals appear in several articles in _The
Mathematical Intelligencer_. This is a quarterly, published
by Springer-Verlag.  It has lots of good articles on
mathematics and related subjects, at a level of difficulty
higher than that of _Scientific American_ but not as high as a
typical research paper.
	Another location for mathematical articles with lots
of meaty content and general interest is the _Bulletin of the
American Mathematical Society._  The Bulletin is addressed primarily 
to university mathematicians, and its articles assume the reader is
familiar with modern math terminology and background.  However,
its survey articles are addressed to as "general" a public as
meets that requirement.

	Here are some articles in which fractal sets, or sets
whose boundaries are fractal, are constructed directly:
(In my references, TMI = _The Mathematical Intelligencer_ and
BAMS = _Bulletin of the AMS_.)

Lenstra, Hendrik W., Jr.  Euclidean number fields 3.
	TMI 2(1979-80)#2, 99-103.
Gilbert, W. J. Fractal geometry derived from complex bases.
	TMI 4(1982)#2, 78-87.
Mandelbrot, Benoit B. Self-inverse fractals osculated by
	sigma-disks and the limit sets of inversion groups.
	TMI 5(1983)#2, 9-17.

	Fractals appear in several ways in the study of
dynamical systems.  One kind of fractal set was studied as far
back as 1919, by Fatou and Julia.  An article with striking
graphics is

Peitgen, H. O., Saipe, D., Haeseler, F.v. Cayley's problem and
	Julia sets. TMI 6(1984)#2,11-20.

	A companion article is:

Blanshard, Paul. Complex analytic dynamics on the Riemann
	sphere. BAMS 11 (1984)#1, 85-142.


	Fractals also appear in dynamical systems as
"attractors."  The terminology seems to be fluid here; fractal
attractors were called "strange" until people got more used to
fractal sets generally, and sometimes were called "chaotic".
To get the straight skinny on these, I recommend starting with

Hirsch, Morris W. The dynmical systems approach to
	differential equations, BAMS, 11 (1984)#1, 1-65

and then 

Ruelle, David. Strange Attractors.
	TMI 2(1979-1980)#4, 126-140.

	Fractal attractors challenge many assumptions we are
likely to take for granted.  When the trajectory of a
dynamical system is attracted to a fractal attractor, it may
appear to repeat its behavior in an vaguely periodic fashion,
but the repetition never settles down to be quite predictable
over a long time span.  A system defined by simple equations,
with behavior that (for a short time) is quite smooth and
easily computable, may over a long time span produce a very
good likeness of a "random" system, whatever that _really_
is. 

Regards,

Chris Henrich
Perkin-Elmer Computer Systems Division
145.7SNOV10::QUODLINGMon Oct 15 1984 06:246
re .2

Some of your 350 programs come up with "Common block not loaded". ??

q

145.8ADVAX::J_ROTHMon Oct 15 1984 11:383
Install PROF77 (the FORTRAN cluster library common)

- Jim