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

/* An ARexx program for creating image panels, to allow calculation */
/* of much higher resolution images for printing. */

/*
	The  maximum size of images that Mand2000 can calculate is set
only by the amount of CHIP (graphics) memory on your Amiga.  Currently
the  amount  of  CHIP  memory  varies  from  512K up to 2MBytes.  With
2MBytes  of  CHIP  memory,  the  largest  images  you  can  create are
approximately  1600x1200  at  256  colours,  or 4000x3500 in black and
white.   If your memory all fragmented, or other programs are running,
it  may be impossible to calculate images of this size.  Normally this
is  plenty  big  enough, as these images are substantially larger than
can   be   displayed  on  the  monitor  without  scrolling  the  image
(autoscroll).  However if you want to print your images, perhaps using
ADPro's  prefprinter  to print multi-page posters to a high-resolution
laser  printer or the Primera dye-sub printer, much higher resolutions
may be desirable.

	This  scripts  provides  the  solution  to this problem.  This
script  will  break  a  picture  up  into a number of different panels
(currently  either  4,  9,  16  or 25) and calculate these separately.
These  panels  can then either be merged in ADPro (if you have lots of
memory  or  GigaMem)  or  can  be printed individually and then pasted
together.

	To  use this script, find the area that you are interested in,
set  up  the palette and the colour mapping option, and set the screen
size  to  a  nice  large size - this screen size will be used for each
panel create by this script.

	Now select `Calculate Panels' from the user menu.  A requester
will appear asking how many panels you would like to calculate.
Select one of these options, then select the base file name.  This
filename will be used for saving out the individual panels.  If you
request 2x2 panels with a base name of `Work:Fractals/BlobPanels' then
the individual panels will be saved to:

Work:Fractals/BlobPanels.0.0	- upper left
Work:Fractals/BlobPanels.1.0	- upper right
Work:Fractals/BlobPanels.0.1	- lower left
Work:Fractals/BlobPanels.1.1	- lower right

	The  first  digit is the x-coordinate of the panel, the second
digit is the y-coordinate of the panel.

	The  final  question  asked  by the script will be whether you
wish to save graphics data or iteration data.  This is VERY important.
If  you  want  to  use ADPro 2.5's Fractal2000 loader to create 24 bit
data from the panels then you MUST save iteration data.  Otherwise you
will almost certainly want to save graphics data.

	At  this point the script will zoom Mand2000 towards the upper
left  hand  corner  of  your picture and begin calculating frames.  It
will  run automatically and will continue until you exit Mand2000, you
cancel  the  script  (by  selecting DoPanels from the user menu) or it
finishes calculating all panels.

	While  Mand2000 is calculating panels you may freely use other
windows in Mand2000, or other programs on your Amiga.

	Nifty things:  This script can be used as a flashy demo of the
power   of  Mand2000's  ARexx  interface  and  of  Mand2000's  general
coolness.   To  do this, set up to do panels just as normal, but use a
substantially  smaller  window  - typically a non-backdrop window on a
moderate  sized  screen.   Before  starting  the  script, select 'Show
location'  from the project window, then zoom the show location window
in  towards the location box so that the location box almost fills the
window.   Now  when  the script is running you will be able to monitor
its  progress  by watching the location box zipping around in response
to ARexx's commands.

	Sometimes  you may have to stop panel creation and then resume
it  at  a later date.  To resume panel creation, go through all of the
steps  to begin creating panels, and then use the `SkipPanel' function
in  the  user  menu  to  skip over those panels that have already been
calculated.  This command has a keyboard shortcut to make it easier to
skip over multiple panels.
	*/

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



/* Parse out the command option.  This script is called when the */
/* user wants a movie started, when the user wants a movie */
/* aborted and whenever one of the pictures in the sequence is done.  */

parse arg command

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

if (command = START) then
	CALL StartPanels()
else if (command = STOP) then
	CALL StopPanels()
else if (command = SKIP) then
	CALL SkipPanels
else
	CALL ContinuePanels()

Exit


StartPanels:
	OKAYN '"Mand2000 panels"' '"How many panels would you like?"' '"2x2|3x3|4x4|5x5|Cancel"'

	if (result = 0) THEN
		exit

	NumRows = result + 1
	NumColumns = NumRows

	REQUESTSAVEFILE 'title="Panel base name."' 'path="RAM:"' 'file="PanelFrame"'

	if (RC = 3) THEN
		exit

	CALL SETCLIP("MandPanelName", result)

	OKAYN '"Mand2000 panels"' '"What type of data would you|like saved?"' '"Iterations|Graphics"'
	if (result = 0) THEN
		CALL SETCLIP("PanelDataType", 1)	/* Graphics. */
	ELSE
		CALL SETCLIP("PanelDataType", 2)	/* Iterations. */

	CALL SETCLIP("NumMandPanelRows", NumRows)
	CALL SETCLIP("NumMandPanelColumns", NumColumns)

	SAVEAS "NAME=RAM:PanelTempFile" 0	/* Save the current location. */

	NEW
	NewPortName = result
	CALL SETCLIP("NewPortName", NewPortName)
	Address value NewPortName
	Requester ShowLoc On
	Address
/*	RequestNotify '"The extra fractal window is for graphically|displaying which panel is being calculated,|using the show location requester.  Select|the panel window from the show location|requester list to make use of this."'*/
	DisplayMessage 0 0 prompt '"The extra fractal window is for graphically|displaying which panel is being calculated,|using the show location requester.  Select|the panel window from the show location|requester list to make use of this."'

	ZOOMINTOPIXEL 0 0 NumRows
	ForceRecalc	/* This is put in here to clear the graphics data which is left by the */
			/* ZoomInToPixel command.  This is purely for aeshetic reasons, and is */
			/* needed because the data no longer corresponds with the new location. */

	GETATTR stem MYVAR

	scroll TRUNC(MYVAR.drawwidth / 2) TRUNC(-1 * MYVAR.drawheight / 2)

	CALL SETCLIP("MandPanelRow", 0)
	CALL SETCLIP("MandPanelColumn", 0)

	EVENTACTION PICTUREDONE DoPanels

	/* Put a command in the user menu for controlling the panel creation. */
	menu '"------------------------"'
	menu '"Stop Panels"' DoPanels stop
	menu '"Skip Panel"' Shortcut V DoPanels skip

	RETURN 0



StopPanels:
	/* Tell Mand2000 not to call this script any more. */
	EVENTACTION PICTUREDONE
	/* Remove the `stop panels' menu. */
	CLEARNMENUS 3
	OPEN "FILENAME=RAM:PanelTempFile"	/* Reload the start location. */
	NewPortName = GETCLIP("NewPortName")
	if (NewPortName ~= "") THEN DO
		DECPAUSE
		REQUESTRESPONSE '"Would you like the display location|window closed?"'
		IF (RC = 0) THEN DO
			Address Value NewPortName
			Close
			Address
		END
		CALL SETCLIP("NewPortName", "")
		INCPAUSE
	END
	RETURN 0



SkipPanels:
	NumRows         = GETCLIP("NumMandPanelRows")
	NumColumns      = GETCLIP("NumMandPanelColumns")
	MandPanelRow    = GETCLIP("MandPanelRow")
	MandPanelColumn = GETCLIP("MandPanelColumn")

	MandPanelColumn = MandPanelColumn + 1
	GETATTR stem MYVAR
	if (MandPanelColumn >= NumColumns) THEN DO
		MandPanelColumn = 0
		MandPanelRow = MandPanelRow + 1
		if (MandPanelRow >= NumRows) THEN DO
			call StopPanels
			DECPAUSE	/* Allow Mand2000 to start calculating while this requester is up. */
			REQUESTNOTIFY "All panels created."
			INCPAUSE	/* Just to be tidy. */
			RETURN 0
			END
		DO iter = 2 to NumRows
			scroll TRUNC(-1 * MYVAR.drawwidth) 0
			END
		scroll 0 TRUNC(-1 * MYVAR.drawheight)
		forcerecalc
		END
	else DO
		scroll MYVAR.drawwidth 0
		forcerecalc
		END
	CALL SETCLIP("MandPanelColumn", MandPanelColumn)
	CALL SETCLIP("MandPanelRow", MandPanelRow)
	RETURN 0



ContinuePanels:
	MandPanelRow    = GETCLIP("MandPanelRow")
	MandPanelColumn = GETCLIP("MandPanelColumn")
	PanelDataType   = GETCLIP("PanelDataType")
	MandPanelName   = GETCLIP("MandPanelName")
	SAVEAS "NAME=" || MandPanelName || "." || MandPanelColumn || "." || MandPanelRow PanelDataType

	CALL SkipPanels

	RETURN 0
