/* Panel loader. */

/*
	This script is a companion to Mand2000's DoPanels.mnd2 script.
DoPanels.mnd2  (accessible  through Mand2000's user menu as `Calculate
Panels')  takes  a  particular  fractal image and recalculates it as a
number  of  separate panels.  Each panel is the same pixel size as the
original, but covers a small portion of the fractal coordinates of the
original.

	These  separate  panels  can then be pasted together by ADPro.
This  allows  you  to calculate images larger than can be displayed in
Chip  RAM.   I  have  used this to calculate images that are 4000x3200
pixels - I then load these into ADPro, using the fractal loader, and I
get beatiful 24 bit colour.

	This  script asks you for the upper left image and the size of
the  grid.  This needn't match what you created.  For instance, if you
created  a  four  by  four  grid of pictures, you can load in the four
corners,  each four by four, as separate operations.  This is handy if
you  are  printing  a multi-page poster and don't have the RAM to hold
all pages at once.

	This   script  assumes  that  the  pictures  were  saved  with
iteration  data,  rather  than  graphics  data.  To change this to use
graphics  data,  the  IFF  loader would have to be used instead of the
Fractal2000 loader.
	*/

address 'ADPro'

options results

getfile '"Select panel for upper left"'
BaseName = adpro_result
if (BaseName = "") THEN
	exit

XCoord = LEFT(RIGHT(BaseName, 3), 1)
YCoord = RIGHT(BaseName, 1)
Basename = LEFT(BaseName, Length(BaseName) - 4)

/* Load the specified file, to see how big it is. */
lformat Fractal2000
load BaseName || "." || XCoord || "." || YCoord
if (RC = 10) THEN DO
	OKAY1 '"Error loading ' || BaseName || "." || XCoord || "." || YCoord || '"'
	exit
END

/* Grab the width and height of the image. */
XSIZE
BaseWidth = adpro_result
YSIZE
BaseHeight = adpro_result

OKAYN '"Mand2000 panels"' '"How big a grid of panels\nwould you like to load?"' '"2x2|3x3|4x4|5x5|Cancel"'
if (rc = 0) THEN
	exit
NumRows = rc + 1

lformat backdrop
load DontCare basewidth * numrows baseheight * numrows color

lformat FRACTAL2000

DO X = 0 to NumRows - 1
	DO Y = 0 to NumRows - 1
		load BaseName || "." || X + XCoord || "." || Y + YCoord    X * basewidth y * baseheight 100
	END
END
