/* This script sets up a custom colour mapping, to demonstrate how */
/* you can take complete control of the colour mapping, to get */
/* perfect pictures.  This particular custom colour map is just */
/* an example of the control you can get.  To get good use out of */
/* this feature you will have to carefully adjust the colour map */
/* creation code to fit each particular picture and you will have */
/* to adjust the palette also. */
/* This script is supplied with the Mand2000 demo and release */
/* versions and may be freely distributed. */
/* Copyright 1993 Cygnus Software. */

/* Note: Custom colourmaps are not supported in the TrueColour modes of */
/* Mand2000. */

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'


/* Parse out the command option.  This script is called when the */
/* user wants a custom colour map turned on, when the user wants a custom */
/* colour map turned off, and whenever the number of iterations or other */
/* colourmap settings change. */

parse arg command

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

if (command = START) then DO
	EVENTACTION COLOURMAPCHANGE CustomColourMap	/* Make sure this script is automatically called. */
	END
else if (command = STOP) then DO
	EVENTACTION COLOURMAPCHANGE	/* Stop this routine from being called anymore. */
	SetColourMap	/* Reset the colour map. */
	Exit
	END

getattr stem WindowVar	/* Get the status structure for the window - put it in WindowVar. */

address value WindowVar.masterarexx	/* Briefly go to the global ARexx port*/
					/* - as specified in the window structure. */
getattr stem GlobalVar

/* Grab the screen depth and calculate the number of colours from that. */
maxcolour = (2 ** GlobalVar.screendepth) - 1
address	/* Reset to the previous port. */

/* Find out the number of iterations. */
maxiters = WindowVar.maxiters

/* Because of the enormous amount of time that it takes ARexx to calculate large colour mappings */
/* this code handles a maximum of 1000 iterations.  It would, however, be fairly easy to write a C */
/* program that would calculate a colour map for 30,000 iterations in a fraction of a second.  */
/* This program could then be called from this script, allowing quite quick turn around. */
if maxiters > 1000 THEN DO
	DISPLAYMESSAGE PROMPT "Calculating a colour map with|this many iterations takes|too long.  Calculating a|colour map for 1000 iterations|instead.  Please wait."
	maxiters = 1000
	END
else if maxiters > 500 THEN
	DISPLAYMESSAGE PROMPT "Please wait - calculating a|colour map with this many|iterations will take a moment."

colour = 5
ITERARRAY = " "
DO iter = 0 to maxiters by 2
	/* Set the colour bands to alternate between colour four and successive colours. */
	/* If you set maxiterations to 30,000 this will be VERY slow!  ARexx is not a fast */
	/* language. */
	IterArray = IterArray || " " || 4 || " " || colour
	colour = colour + 1
	if (colour > MaxColour) THEN
		colour = 5
	END
/* Tell Mand2000 to use colour 0 for the Mandelbrot set (default is colour 1) and to */
/* use the array of colour numbers we built up in IterArray. */

if maxiters > 500 THEN
	DISPLAYMESSAGE OFF

SetColourMap 0   IterArray
