Re: [S] animation and pausing

Chuck Taylor (chuck@statsci.com)
Fri, 3 Apr 1998 15:39:35 -0800 (PST)


Earlier I responded privately to a request from Terje Jorgensen for
information about animation in S-PLUS 4.0. Since then other people
including Tony Plate and Brian Ripley have expressed interest in the
topic. Perhaps others are interested as well, so I am responding publicy
to Professor Ripley's request for more technical information.

The original request from Terje Jorgensen was as follows:

> To create animation, I want the result of each plotting command within a
> function to be displayed immediately upon completion of that command.
> As is, everything is plotted upon exit (return) from the function.
>
> How can I force the immediate display to a graphic window of the result
> of a plotting command that is part of a function?

On Fri, 3 Apr 1998, Prof Brian Ripley wrote in response to a comment by
Tony Plate about animation with S-PLUS for Unix:

> I assume we are talking about using a motif/openlook graphics device under
> Unix, and a graphsheet under S-PLUS 4.0. ... The fundamental
> difference is that under Unix the graphics devices run as a separate
> process connected by a pipe, and normal Unix multi-tasking applies. I
> don't know how S-PLUS 4.0 is actually implemented, but it is reported by
> Windows 95 as a single task with a single thread. If this is accurate
> ...

Professor Ripley is correct that S-PLUS 4.0 runs as a single thread.

> This seems a technical question for the designers of 4.0. Would
> someone at MathSoft care to respond?

Our lead graphics developer had this to say:

"In S-PLUS 4.x, low level graphics calls are "collected" into composite
objects (when in fast mode), and then drawn. These composite objects can
be saved and loaded (within a graph sheet), exported to other file
formats, and converted to editable objects. A new composite object is
created each time a set of graphics calls is sent from the command line,
or when a script is run.

"For example, typing at the command line:

> plot(1:10)
> lines(1:10)

will create two composite objects. These can be seen in the object
browser, and can independently be converted to objects if editing of
only part of the graph is desired.

"But,

> plot(1:10); lines(1:10)

creates a single composite object, as does a script containing

plot(1:10)

followed by

lines(1:10)

"The screen will be updated and a new composite object created if a call
to guiLocator(-n) is made, where n is the number of seconds to pause
before continuing. A script or function containing:

plot(1:10)
guiLocator(-1)
lines(1:10)

will show the initial plot, pause for one second, and add the lines.

"Similarly, the following script

graphsheet( pages = "Off")
plot(1:10)
guiLocator( -1 )
plot( 1:20 )

will draw the first plot, pause for 1 second, and then replace it with
the second. Since the first plot is replaced with the second, you will
end up with a single composite object."

These comments refer to S-PLUS 4.0 Releases 2 and 3 and the
soon-to-be-released Version 4.5. Release 1 does not support animation.
(Specifically, guiLocator() does not accept a negative argument in
Release 1.) By "fast mode" we mean traditional command-line S-PLUS
graphics (also called "composite graphics") as opposed to the
object-oriented graphics created from the graphical user interface, or
from the command line with "Editable Objects" toggled on.

The following function illustrates simple animation in S-PLUS 4.x. It
should be run in "fast mode".

"animate"<-
function(n = 10, speed = 100)
{
delay <- -1/speed
plot(1:n, 1:n, type = "n")
for(i in 2:n) {
guiLocator(delay)
lines((i - 1):i, (i - 1):i, type = "l")
}
}

Running this in 4.0 Release 2, or 3 or in the 4.5 Beta version does result
in some flicker, depending on the speed of your machine. Flicker is
significantly reduced in the release version of 4.5. Attempting to run
this function in Release 1 will produce an error.

|-----------------------------------|
| Chuck Taylor |
| Senior Quality Assurance Engineer |
| MathSoft Seattle, WA, USA |
|-----------------------------------|

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news