/* This script is supplied with the Mand2000 demo and release */
/* versions and may be freely distributed. */
/* Copyright 1993 Cygnus Software. */

/* An ARexx script for imitating the Demo Mode of the earlier */
/* versions of Mand2000.  This script zooms in (with pauses for */
/* calculations) towards various beautiful locations specified */
/* in the script.  When it reaches them it resets and zooms towards */
/* another location. */

/*
	By   duplicating   or   removing  some  code  at  the  end  of
ContinueDemo:   you can adjust how many zooms Mand2000 does per stage.
If  you set it to do just one zoom then the demo runs rather tediously
slow.

	If you don't want the status window you should comment out the
DisplayMessage lines at the end of NewLocation and ContinueDemo.
	*/

portname = address()	/* Retrieve the current port name. */
/* If the portname does not start with MAND2000 then this script must */
/* have been run with rx, rather than from Mand2000.  Therefore we */
/* need to set the port name.  We do not always set the port name */
/* because it is better to let Mand2000 set it for us, so that */
/* this script can be used with windows other than the one with */
/* port name MAND2000.1. */
if (left(portname, 8) ~= "MAND2000") THEN
	address 'MAND2000.1'

options results

/*
	The  following code sets up the coordinates of the pictures to
zoom  towards  when  running  the  demo.   The format should be fairly
obvious  from  the  examples below.  IMPORTANT:  before adding any new
locations, or making any other changes to this file, be sure to make a
backup  copy, as it is very easy to make syntax errors which will make
this script stop working.

	The  name  of  the location must be enclosed in quotes.  The X
and  Y  coordinates  are  the coordinates of the center of the spot to
zoom  towards.   Zooms  is the number of zooms to do before going onto
the  next  picture.   Type  is the fractal type.  Usually this will be
'Mandelbrot'  or  'Mandelbrot  Julia'.   If you specify Julia then you
should also specify JuliaReal and JuliaImaginary (see Julia Boot as an
example)  as  these  specify the Julia's seed location.  If you have a
math  coprocessor  (68881,  68882  or  68040)  then  you also have the
MandCubed  and  MandFourth  fractal  types, and their associated julia
sets  -  see  the  help  on set location for details.  Optionally, for
those  areas that require it, you can specify that the location should
have  a  higher than normal Max Iterations, by setting ExtraIterations
to  the  number  of iterations beyond the normal for the pictures zoom
level, that you would like.  See the example.

	It  is very important when entering new numbers to ensure that
your  numbers  are  correct - no spaces or commas allowed in numbers -
and  that  the index number is the same for all the lines describing a
particular location.  The index number is the number immediately after
'Pictures'.  It is also very important to enclose the location numbers
in quotes, as in the examples below.  If you don't then ARexx will try
to  interpret  the  numbers.   Usually  this  is okay, but many of the
numbers  have more digits of accuracy than ARexx can handle, and these
extra digits will get lost without the quoting.

	It is also important that the final entry have a zoom count of
zero so that the code will no when to return to the first entry.

	Currently  this  script  is set up so that if you run it, then
stop,  then  run  it  again,  it  will  resume on the same picture you
stopped  on  (although  not  the  same zoom level).  If this behaviour
causes  problems, or if this script encounters an error and ends up in
an  undefined  state,  comment  out  the  line  below  which  says 'if
(DemoPictureNum   =  "")  THEN'  by  enclosing  it  in  ARexx  comment
delimiters,  like  this '/* if (DemoPictureNum = "") */'.  Do not type
the  quotes.   The  line  is  clearly  marked and is shortly after the
StartDemo:  label.

	If you run this script several times in a row without stopping
it,  you  will  end  up with multiple 'Stop Demo' entries in your user
menu.   These can be removed by repeatedly selecting 'Stop Demo' until
they are all gone.

	If  for  some  reason  you  can  not  get  this script to stop
running,  you  may  need to exit Mand2000.  This should only happen if
there is a bug in the ARexx script.

	For  more  information,  consult  your  ARexx  manual  or  the
Mand2000 ARexx documentation.
	*/

DemoPictureNum = 0

Pictures.DemoPictureNum.Name = "Julia Boot"
Pictures.DemoPictureNum.X = "0"
Pictures.DemoPictureNum.Y = "0"
Pictures.DemoPictureNum.JuliaReal = "0.329"
Pictures.DemoPictureNum.JuliaImaginary = "0.041"
Pictures.DemoPictureNum.Zooms = 4
Pictures.DemoPictureNum.Type = "Mandelbrot JULIA"
Pictures.DemoPictureNum.ExtraIterations = 0
DemoPictureNum = DemoPictureNum + 1

Pictures.DemoPictureNum.Name = "Dragon"
Pictures.DemoPictureNum.X = "-1.25269"
Pictures.DemoPictureNum.Y = "-0.04164"
Pictures.DemoPictureNum.Zooms = 12
Pictures.DemoPictureNum.Type = "Mandelbrot"
Pictures.DemoPictureNum.ExtraIterations = 0
DemoPictureNum = DemoPictureNum + 1

Pictures.DemoPictureNum.Name = "Off axis filaments"
Pictures.DemoPictureNum.X = "-1.74910040"
Pictures.DemoPictureNum.Y = "-0.00034817"
Pictures.DemoPictureNum.Zooms = 25
Pictures.DemoPictureNum.Type = "Mandelbrot"
Pictures.DemoPictureNum.ExtraIterations = 0
DemoPictureNum = DemoPictureNum + 1

Pictures.DemoPictureNum.Name = "Six arms"
Pictures.DemoPictureNum.X = "-.8627"
Pictures.DemoPictureNum.Y = "0.2648"
Pictures.DemoPictureNum.Zooms = 10
Pictures.DemoPictureNum.Type = "Mandelbrot"
Pictures.DemoPictureNum.ExtraIterations = 0
DemoPictureNum = DemoPictureNum + 1

Pictures.DemoPictureNum.Name = "Nautilus"
Pictures.DemoPictureNum.X = "-1.98540769643288"
Pictures.DemoPictureNum.Y =  "0.00000000000470"
Pictures.DemoPictureNum.Zooms = 38
Pictures.DemoPictureNum.Type = "Mandelbrot"
Pictures.DemoPictureNum.ExtraIterations = 0
DemoPictureNum = DemoPictureNum + 1

Pictures.DemoPictureNum.Name = "Paisley"
Pictures.DemoPictureNum.X = "0.306594"
Pictures.DemoPictureNum.Y = "0.023627"
Pictures.DemoPictureNum.Zooms = 10
Pictures.DemoPictureNum.Type = "Mandelbrot"
Pictures.DemoPictureNum.ExtraIterations = 0
DemoPictureNum = DemoPictureNum + 1

Pictures.DemoPictureNum.Name = "Twelve arms"
Pictures.DemoPictureNum.X = "-.7764"
Pictures.DemoPictureNum.Y = "0.1346"
Pictures.DemoPictureNum.Zooms = 12
Pictures.DemoPictureNum.Type = "Mandelbrot"
Pictures.DemoPictureNum.ExtraIterations = 0
DemoPictureNum = DemoPictureNum + 1

Pictures.DemoPictureNum.Name = "Russian circles"
Pictures.DemoPictureNum.X = "-1.98540769644835784"
Pictures.DemoPictureNum.Y =  "0.0"
Pictures.DemoPictureNum.Zooms = 50
Pictures.DemoPictureNum.Type = "Mandelbrot"
Pictures.DemoPictureNum.ExtraIterations = 0
DemoPictureNum = DemoPictureNum + 1

Pictures.DemoPictureNum.Name = "Spiral Galaxy"
Pictures.DemoPictureNum.X = "-0.7782"
Pictures.DemoPictureNum.Y =  "0.13504"
Pictures.DemoPictureNum.Zooms = 10
Pictures.DemoPictureNum.Type = "Mandelbrot"
Pictures.DemoPictureNum.ExtraIterations = 0
DemoPictureNum = DemoPictureNum + 1

Pictures.DemoPictureNum.Name = "Fuzzy spirals"
Pictures.DemoPictureNum.X = ".15753543"
Pictures.DemoPictureNum.Y = "0.63759561"
Pictures.DemoPictureNum.Zooms = 23
Pictures.DemoPictureNum.Type = "Mandelbrot"
Pictures.DemoPictureNum.ExtraIterations = 0
DemoPictureNum = DemoPictureNum + 1

Pictures.DemoPictureNum.Name = "Crossing Spirals"
Pictures.DemoPictureNum.X = "-0.4658325"
Pictures.DemoPictureNum.Y =  "-0.548969"
Pictures.DemoPictureNum.Zooms = 21
Pictures.DemoPictureNum.Type = "Mandelbrot"
Pictures.DemoPictureNum.ExtraIterations = 0
DemoPictureNum = DemoPictureNum + 1

Pictures.DemoPictureNum.Name = "Axis mand"
Pictures.DemoPictureNum.X = "-1.941"
Pictures.DemoPictureNum.Y =  "0"
Pictures.DemoPictureNum.Zooms = 10
Pictures.DemoPictureNum.Type = "Mandelbrot"
Pictures.DemoPictureNum.ExtraIterations = 0
DemoPictureNum = DemoPictureNum + 1

Pictures.DemoPictureNum.Name = "Fingers"
Pictures.DemoPictureNum.X = "-1.2400805220702"
Pictures.DemoPictureNum.Y =  "0.4165960742914"
Pictures.DemoPictureNum.Zooms = 39
Pictures.DemoPictureNum.Type = "Mandelbrot"
Pictures.DemoPictureNum.ExtraIterations = 0
DemoPictureNum = DemoPictureNum + 1

Pictures.DemoPictureNum.Name = "Inside Mitosis"
Pictures.DemoPictureNum.X = "-0.776526256"
Pictures.DemoPictureNum.Y =  "0.134646536"
Pictures.DemoPictureNum.Zooms = 26
Pictures.DemoPictureNum.Type = "Mandelbrot"
Pictures.DemoPictureNum.ExtraIterations = 300
DemoPictureNum = DemoPictureNum + 1


Pictures.DemoPictureNum.Zooms = 0	/* This marks the end of the list. */



/* Parse out the command option.  This script is called when the */
/* user wants demo mode started, when the user wants demo mode terminated */
/* and whenever one of the demo frames is finished. */

parse arg command

command = upper(command)	/* Make sure the command is in upper case. */

if (command = START) then
	CALL StartDemo()
else if (command = STOP) then
	CALL StopDemo()
else
	CALL ContinueDemo()

Exit



StartDemo:
	DemoPictureNum = GETCLIP("DemoPictureNum")
	/* Comment out the following line if you want this script to always */
	/* restart at frame zero when you rerun it. */
	if (DemoPictureNum = "") THEN
		DO
		DemoPictureNum = 0
		CALL SETCLIP("DemoPictureNum", DemoPictureNum)
		END
	CALL NewLocation()
	EVENTACTION PICTUREDONE Demo

	/* Put a command in the user menu for stopping the movie creation. */
	menu '"------------------------"'
	menu '"Stop Demo"' Demo stop
	RETURN 0



StopDemo:
	/* Tell Mand2000 not to call this script any more. */
	EVENTACTION PICTUREDONE
	/* Remove the `stop iter movie' menu. */
	CLEARNMENUS 2
	DISPLAYMESSAGE off
	RETURN 0



ContinueDemo:
	DemoPictureNum = GETCLIP("DemoPictureNum")
	GETATTR stem PROJ
	if (PROJ.NumZooms >= Pictures.DemoPictureNum.Zooms) THEN DO
		DemoPictureNum = DemoPictureNum + 1
		if (Pictures.DemoPictureNum.Zooms = 0) THEN	/* End of list */
			DemoPictureNum = 0
		CALL SETCLIP("DemoPictureNum", DemoPictureNum)
		CALL NewLocation()
		RETURN 0
		END

	ZoomInToFloat Pictures.DemoPictureNum.X Pictures.DemoPictureNum.Y

	/* Comment out the following two lines if you only want the demo to do one zoom */
	/* at a time.  Replicate the following three lines if you want the demo to do */
	/* additional zooms each time. */
	GETATTR stem PROJ
	if (PROJ.NumZooms < Pictures.DemoPictureNum.Zooms) THEN
		ZoomInToFloat Pictures.DemoPictureNum.X Pictures.DemoPictureNum.Y

	GETATTR stem PROJ
	DisplayMessage 0 0 prompt "Calculating:" Pictures.DemoPictureNum.Name || "|Zoom" PROJ.NumZooms "of" Pictures.DemoPictureNum.Zooms || "|Select 'Stop Demo' to stop"
	RETURN 0



NewLocation:
	RESET
	SETFRACTALTYPE Pictures.DemoPictureNum.Type
	if (Pictures.DemoPictureNum.JuliaReal ~= "") THEN
		SETJULIA Pictures.DemoPictureNum.JuliaReal Pictures.DemoPictureNum.JuliaImaginary
	/* Remove the comments on the following line if you want the pictures */
	/* name printed to the CLI when a new pictures starts calculating. */
	/* say Pictures.DemoPictureNum.Name*/

	MaxIters 75 + Pictures.DemoPictureNum.ExtraIterations

	/* Comment out the following line if you don't want the status window. */
	DisplayMessage 0 0 prompt "Calculating:" Pictures.DemoPictureNum.Name || "|Zoom 0 of" Pictures.DemoPictureNum.Zooms || "|Select 'Stop Demo' to stop"
	RETURN 0
