[S] animation and pausing

Tony Plate (Tony.Plate@mcs.vuw.ac.nz)
Fri, 03 Apr 1998 09:30:37 +1200


Terje Jorgensen writes:

>I did not get any feedback on my previous submisssion of this query to the
>list so I take the liberty of re-submitting it.
>
>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?

> [the code Terje provides used a busy wait to pause for one second between
> plotting each point, but the display was not updated until the entire
> function completed.]

I can't help you directly, as I don't run S+ under windows,
but I wonder if your problem is the busy wait you use for
pause().

Under Unix, the normal behaviour of the plot(), points(), etc. commands
is to immediately display the resulting graphic.

When I run the following under unix, it works fine, plotting
one point every second.

(function(n)
{
# Plot three point, one at a time.
# Display each point once plotted.
x<- c(1,2,3)
y<- c(1,2,1)
plot(x,y, type="n")
nobs <- length(x)
for(i in 1:nobs) {
points(x[i], y[i]) # plot one point
cat(paste("Plotted", x[i], y[i], "\n"))
unix(paste("sleep", 2)) # and pause for n sec
}
})(1)

I suspect what is happenning with your function is that
the processor is spending all its time in the busy wait loop,
and doesn't get around to drawing the points until the loop
is finished.

Indeed, your version with the busy wait also runs fine under
unix, but unix has much better processor sharing than windows.

What I'd suggest you do is find a better way of pausing under
windows.

Try looking in the archives, I think this has been discussed
before.

cheers,

Tony Plate

In message <3.0.32.19980402171229.00acb290@hipost.imr.no>, Terje Jorgensen writ
es:
>Dear S+ Users,
>
>I did not get any feedback on my previous submisssion of this query to the
>list so I take the liberty of re-submitting it.
>
>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?
>
>I am running v. 4.0 release 3 for Windows.
>
>Example:
>
>test.plot<- function(n)
>{
># Plot three point, one at a time.
># Display each point once plotted.
>
> x<- c(1,2,3)
> y<- c(1,2,1)
>
> plot(x,y, type="n")
>
> nobs <- length(x)
> for(i in 1:nobs) {
> points(x[i], y[i]) # plot one point
> pause(n) # and pause for n sec
> }
>}
>
>
>
>The pause function was kindly provided by Bert Gunter
>pause<- function(n)
>{
> start <- proc.time()
> while(proc.time() < (start + n)) {
>#do nothing
> }
> cat("all done\n")
>}
>
>Thanks in advance!
>
>
>Terje Jorgensen
>Gear Section
>Institute of Marine Research, Bergen
>Norway
>
>e-mail: terjej@imr.no
>
>-----------------------------------------------------------------------
>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

-----------------------------------------------------------------------
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