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


/* Set the total number of frames to be calculated. */

NumFrames = 15



/*
	This script is for calculating Julia seed movies.  As you drag
the  Julia  seed  across  the  Mandelbrot  set  the  Julia set changes
dramatically,  and  this  script  allows  you  to  easily calculate an
animation  of  these  changes,  thus allowing you to play them back in
real time.

	This  script  takes the julia seed location when you initially
run the script as the start point, and then asks you to select another
point.   It  then smoothly moves from one pointer to the other, saving
the frames out as calculated.  If you ask it to save out full screens,
then the Mandelbrot set with the seed pointer moving across it will be
saved also, showing the cause and effect.

	The  number  of  frames  calculated  can  easily be changed by
adjusting the variable at the top of the script.

	The  resulting  sequence  of  frames can be easily loaded into
DPaint or any other program for creating animations.

	This script will, optionally, use ADPro to create an animation
file  out  of the individual frames as they are generated.  This saves
time  and  reduces  the  user intervention required to create a movie.
Also,  if the script were modified so that the frames were deleted off
of the disk as soon as they had been put into the Anim, the disk space
required would be reduced.
	*/

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 StartJULIAMovie()
else if (command = STOP) then
	CALL StopJULIAMovie()
else
	CALL ContinueJULIAMovie()

Exit



StartJULIAMovie:
	GETATTR stem PROJ
	/* Julia fractal types are always odd. */
	if ((PROJ.FRACTALTYPE // 2) ~= 1) THEN DO
		DISPLAYMESSAGE PROMPT "A Julia window must be active when|making these movies.  Please|activate a Julia window and try|again."
		EXIT
		END

	GETATTR stem PROJ
	StartX = PROJ.JuliaX
	StartY = PROJ.JuliaY
	CALL SETCLIP("JuliaMovieStart.X", PROJ.JuliaX)
	CALL SETCLIP("JuliaMovieStart.Y", PROJ.JuliaY)

	DECPAUSE		/* Allow Mand2000 to resume calculating while this script executes. */

	REQUESTER JULIASEED	/* See whether the julia seed requester is up already. */
	juliaseedstate = RESULT
	REQUESTER JULIASEED ON	/* Force it to be up regardless. */

	REQUESTNOTIFY "The current seed location will be|used as the animation start.|Select the end seed location and|click `Continue'."

	GETATTR stem PROJ
	CALL SETCLIP("JuliaMovieEnd.X", PROJ.JuliaX)
	CALL SETCLIP("JuliaMovieEnd.Y", PROJ.JuliaY)

	/* Turn the julia seed requester off, if that's how it started. */
	if (juliaseedstate = 0) THEN
		REQUESTER JULIASEED OFF

	/* Put a command in the user menu for stopping the movie creation. */
	menu '"------------------------"'
	menu '"Stop Julia Movie"' JuliaMovie stop

	INCPAUSE		/* Stop calculations again. */
	CALL SETCLIP("Mand2000FrameNum", 10001)
	/* Tell Mand2000 to call this script whenever a pictures finishes calculating. */
	EVENTACTION PICTUREDONE JuliaMovie

	/* Assume that ADPro is not wanted. */
	CALL SETCLIP("JULIATOADPRONAME")
	/* Then ask if it is. */
	REQUESTRESPONSE "Would you like the frames|written to an anim file|by ADPro?"
	if (RC = 0) THEN DO
		REQUESTSAVEFILE 'title="Julia anim file name."' 'path="RAM:"' 'file="JuliaAnim"'
		CALL SETCLIP("JULIATOADPRONAME", result)
		END

	/* Assume that window only is wanted. */
	CALL SETCLIP("JULIAWINDOWONLY", 1)
	/* Then ask if it is. */
	REQUESTRESPONSE "Would you like full screen|images saved?"
	if (RC = 0) THEN DO
		CALL SETCLIP("JULIAWINDOWONLY", 0)
		END

	SETJULIA StartX StartY
	RETURN 0



StopJULIAMovie:
	/* Tell Mand2000 not to call this script any more. */
	EVENTACTION PICTUREDONE
	/* Remove the `stop Julia movie' menu. */
	CLEARNMENUS 2
	FRAMENUM = GETCLIP("Mand2000FrameNum")
	if (FRAMENUM = "") THEN
		EXIT
	CALL SETCLIP("Mand2000FrameNum")
	AnimName = GETCLIP("JULIATOADPRONAME")
	if (AnimName ~= "") THEN DO
		if ~show('p',"ADPro") THEN
			EXIT
		/* Start sending commands to ADPro. */
		ADDRESS "ADPro"
		/* Specify that we want to save an animation file. */
		SFORMAT Anim
		/* Save as anim frame. */
		SAVE AnimName IMAGE WRAPUP BYTE FASTER
		Why = ADPRO_RESULT
		if (RC ~= 0) THEN DO
			REQUESTNOTIFY "Error in wrap up.|Aborting animation."
			CALL StopJULIAMovie()
			EXIT
			END
		/* Resume sending commands to Mand2000. */
		ADDRESS
		if (FRAMENUM = 10001) THEN
			REQUESTNOTIFY "Zero frames created."
		else if (FRAMENUM = 10002) THEN
			REQUESTNOTIFY "One frame created."
		else
			REQUESTNOTIFY "Just created a "FRAMENUM - 10001" frame anim.|Use DPaint or View to play it."
		EXIT
		END
	if (FRAMENUM = 10001) THEN
		REQUESTNOTIFY "Zero frames created."
	else if (FRAMENUM = 10002) THEN
		REQUESTNOTIFY "One frame created."
	else
		REQUESTNOTIFY "Just created "FRAMENUM - 10001" Julia frames.|Use ADPro or DPaint to make these|into an animation."
	RETURN 0



ContinueJULIAMovie:
	FRAMENUM = GETCLIP("Mand2000FrameNum")
	WINDOWONLY = GETCLIP("JULIAWINDOWONLY")
	if (WINDOWONLY = 1) THEN
		SAVEAS "NAME=RAM:JULIAFRAME"FRAMENUM 1	/* Save the location and graphics (type 1) of the frame. */
	ELSE
		SAVESCREENAS "NAME=RAM:JULIAFRAME"FRAMENUM
	if (RC ~= 0) THEN DO
		REQUESTNOTIFY "Error in saving frame "FRAMENUM".|Aborting animation."
		CALL StopJULIAMovie()
		EXIT
		END
	AnimName = GETCLIP("JULIATOADPRONAME")
	if (AnimName ~= "") THEN DO
		if ~show('p',"ADPro") THEN DO
			REQUESTNOTIFY "Error - ADPro is not running.|Aborting animation."
			CALL StopJULIAMovie()
			EXIT
			END
		/* Start sending commands to ADPro. */
		ADDRESS "ADPro"
		/* Specify that we want to load an IFF file. */
		LFORMAT IFF
		/* Load the last generated frame, don't bother converting to 24 bit. */
		Load "RAM:JULIAFRAME"FRAMENUM nopad
		if (RC = 10) THEN DO
			REQUESTNOTIFY "Error in loading to ADPro.|Aborting animation."
			CALL StopJULIAMovie()
			EXIT
			END
		/* Specify that we want to save an animation file. */
		SFORMAT Anim
		/* Save as anim frame. */
		SAVE AnimName IMAGE APPEND BYTE FASTER
		Why = ADPRO_RESULT
		if (RC ~= 0) THEN DO
			REQUESTNOTIFY "Error in anim save.|Aborting animation."
			CALL StopJULIAMovie()
			EXIT
			END
		/* Resume sending commands to Mand2000. */
		ADDRESS
		/* At this point the IFF file could be deleted from the RAM disk. */
		END
	FRAMENUM = FRAMENUM + 1
	CALL SETCLIP("Mand2000FrameNum", FRAMENUM)

	FRAMENUM = FRAMENUM - 10001	/* Subtract off the starting frame number. */
	IF (FRAMENUM > (NumFrames - 1)) THEN DO
		CALL StopJuliaMovie()
		EXIT
		END
	DONERATIO = FRAMENUM / (NumFrames - 1)	/* Calculate doneratio to be between 0.0 and 1.0. */
	StartX = GETCLIP("JuliaMovieStart.X")
	StartY = GETCLIP("JuliaMovieStart.Y")
	EndX = GETCLIP("JuliaMovieEnd.X")
	EndY = GETCLIP("JuliaMovieEnd.Y")

	/* Calculate a new julia seed, part way between start and end. */
	NewX = StartX + (EndX - StartX) * DONERATIO
	NewY = StartY + (EndY - StartY) * DONERATIO

	/* Set a new julia seed. */
	SETJULIA NewX NewY
	RETURN 0
